Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

create List c#

using System.Collections.Generic
//type is your data type (Ej. int, string, double, bool...)
List<type> newList = new List<type>();
Comment

make a list c#

IList<int> newList = new List<int>(){1,2,3,4};
Comment

Create list C#

var list = new List<string> {
  "test1",
  "test2",
  "test3"
};
Comment

Create list C#


var list = new List<string> { "test1", "test2", "test3" };

Comment

how to create a list c#

C# By Magnificent Mamba on Dec 23 2019
IList<int> newList = new List<int>(){1,2,3,4};
Comment

c# new list of objects

var list = new List<Object>()
Comment

c# create list of objects

public class Car
    {
        private int intYear;
        private string strCar;
        private DateTime dtRelease;
        public Car(int intYear, string strCar, DateTime dtRelease)
        {
            this.intYear = intYear;
            this.strCar = strCar;
            this.dtRelease = dtRelease;
        }

        public int IntYear { get => intYear; set => intYear = value; }

        public string StrCar { get => strCar; set => strCar = value; }

        public DateTime DtRelease { get => dtRelease; set => dtRelease = value; }

    }

static void Main(string[] args)
        {
            List<Car> objCars = new List<Car>();
            objCars.Add(new Car(2022, "BMW", new DateTime(2017, 3, 1).Date));
            objCars.Add(new Car(2022, "Honda", new DateTime(2019, 2, 1).Date));
            objCars.Add(new Car(2022, "Mercedes", new DateTime(1998, 1, 1).Date));

            foreach (Car cars in objCars){
                Console.WriteLine("----------------");
                Console.WriteLine(cars.IntYear);
                Console.WriteLine(cars.StrCar);
                Console.WriteLine(cars.DtRelease);
            }
        }
//Output:

//----------------
//2022
//BMW
//01.03.2017 00:00:00
//----------------
//2022
//Honda
//01.02.2019 00:00:00
//----------------
//2022
//Mercedes
//01.01.1998 00:00:00

Comment

create list of strings from field of list of object c#

//ConvertAll - Converts the elements in the current List to another
//type, and returns a list containing the converted elements
List<string> ls = sampleList.ConvertAll(item => item.IneedThis)
Comment

PREVIOUS NEXT
Code Example
Csharp :: scale between tow ranges c# 
Csharp :: how to make a 3d object do something when clicked on 
Csharp :: adding a dependency injection service in windows forms app 
Csharp :: autfac .net 6 
Csharp :: c# yield keyword 
Csharp :: mvc string format 
Csharp :: c# type of string 
Csharp :: variable size in memory c# 
Csharp :: unity switch to scene and transfer data 
Csharp :: c# draw rectangle on screen 
Csharp :: on trigger unity 
Csharp :: instantiate prefab unity 
Csharp :: sequelize top 
Csharp :: convert object to iqueryable in c# 
Csharp :: migrationbuilder insert data example 
Csharp :: c# sum object values 
Csharp :: listbox items to string c# 
Csharp :: c# obsolete class 
Csharp :: fluent api 
Csharp :: Disable Debug.log Unity 
Csharp :: adding to a dictionary unity 
Csharp :: string interpolation in c# 
Csharp :: c# webapi return file 
Csharp :: C# Linq item index 
Csharp :: unity dropdown 
Csharp :: scene manager load scene 
Csharp :: c# loop 2 time tables 
Csharp :: declarar lista c# 
Csharp :: how to fade c# form 
Csharp :: sto playing audiosource 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =