Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

combine two lists c#

List<string> a = new List<string>();
List<string> b = new List<string>();

a.AddRange(b);
Comment

c# merge two lists

// Create your object
public class A { int Id { get; set; } A() { } A(int id) { Id = id;} }
public class B { int Id { get; set; } B() { } B(int id) { Id = id;} }

// Construct your lists
List<A> list = new List<A>() { new A( Id = 1 ), new A( Id = 2 ) };
List<B> list1 = new List<B>() { new B( Id = 3 ), new B( Id = 4 ) };

// Then create a linq query and convert the result to a list
List<object> all = (from x in list select (object)x).ToList();

// Now add the second list to the end of the last one
all.AddRange((from x in list1 select (object)x).ToList());

// You can use this new list to loop it like this
foreach (object item in all)
{
	// If you want to check which object we are looping you do this:
	bool obj1 = item is A;
	// Now you can cast the item to your object in a conditional operator
	Console.WriteLine(obj1 ? (item as A).Id : (item as B).Id);

	// Output:
	// 1
	// 2
  	// 3
  	// 4
}
Comment

c# merge two lists with return

var newList = a.Concat(b);
Comment

concatanate two lists in c#

using System;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        List<string> Fruits = new List<string>() { "Apple", "Banana", "Orange", "Mango" };
        List<string> Vegetables = new List<string>() { "Potato", "Tomato", "Cauli Flower", "Onion" };
        Fruits.AddRange(Vegetables);
        Console.Write("Fruits and Vegetables are: ");
        Console.WriteLine(String.Join(",", Fruits));
    }
}
Comment

concatenate two lists in c#

		List<int> lst1 = new List<int>(){1,2,3,4,5};
		List<int> lst2 = new List<int>(){6,7,8,9};
		foreach(var i in lst2){
			lst1.Add(i);
		}
        // lst1 : {1,2,3,4,5,6,7,8,9}
        // lst2 : {6,7,8,9}
Comment

c# merge two lists different types

// Create your object
public class A { int Id { get; set; } A() { } A(int id) { Id = id;} }
public class B { int Id { get; set; } B() { } B(int id) { Id = id;} }

// Construct your lists
List<A> list = new List<A>() { new A( Id = 1 ), new A( Id = 2 ) };
List<B> list1 = new List<B>() { new B( Id = 3 ), new B( Id = 4 ) };

// Then create a linq query and convert the result to a list
List<object> all = (from x in list select (object)x).ToList();

// Now add the second list to the end of the last one
all.AddRange((from x in list1 select (object)x).ToList());

// You can use this new list to loop it like this
foreach (object item in all)
{
	// If you want to check which object we are looping you do this:
	bool obj1 = item is A;
	// Now you can cast the item to your object in a conditional operator
	Console.WriteLine(obj1 ? (item as A).Id : (item as B).Id);

	// Output:
	// 1
	// 2
  	// 3
  	// 4
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: ts partial record 
Typescript :: typescript array with allowed object keys 
Typescript :: typescript type from enum values 
Typescript :: typescript window ethereum 
Typescript :: how to get post of instragram using api 
Typescript :: three dots dropdown menu bootstrap 
Typescript :: typescript recursive partial 
Typescript :: Implement a function that accepts 3 integer values a, b, c. The function should return true if a triangle can be built with the sides of given length and false in any other case. 
Typescript :: git lits file in commit 
Typescript :: passing data to a MatDialog component using inject 
Typescript :: @react-navigation/native route typescript 
Typescript :: alert angular 
Typescript :: change textinputlayout color 
Typescript :: stylesheet not loaded because of mime-type 
Typescript :: html5 download tag not working 
Typescript :: reported error code “128” when it ended: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 
Typescript :: To list all tcp ports. 
Typescript :: react.children 
Typescript :: vertical dots latex 
Typescript :: typeorm query builder update relations filed 
Typescript :: extend type typescript 
Typescript :: mark occurances of elements in array cpp 
Typescript :: python requests use proxy 
Typescript :: typescript props class component 
Typescript :: laravel validation check if email exists forget password 
Typescript :: create custom user properties firebase 
Typescript :: google sheets new line 
Typescript :: java lambda list of objects cast 
Typescript :: targe id that starts with 
Typescript :: simulate click typescript 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =