Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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

PREVIOUS NEXT
Code Example
Csharp :: array sort C Sharp 
Csharp :: check property type of collection c# 
Csharp :: c# public static string 
Csharp :: c# get custom attribute from property 
Csharp :: datetime month name 
Csharp :: c# linq select as new object 
Csharp :: if checkbox checked in c# 
Csharp :: c# template 
Csharp :: c# string list 
Csharp :: priority queue c# 
Csharp :: how to get current dir in c# 
Csharp :: from string 
Csharp :: dotween sequence 
Csharp :: c# remove duplicates from list 
Csharp :: unity rigid body variable 
Csharp :: simple code to call rest api c# 
Csharp :: all substrings of a string c# 
Csharp :: c# random number between 0 and 1 
Csharp :: unity render to texture2d 
Csharp :: unity gameobject find inactive 
Csharp :: Raycasting to find mouseclick on Object in unity 2d games 
Csharp :: c# draw rectangle on screen 
Csharp :: c# arrow 
Csharp :: remove item from list in for loop c# 
Csharp :: string to array c# 
Csharp :: mysqldump - date 
Csharp :: unity reflect raycast 
Csharp :: calculator in c# 
Csharp :: c# datagridview set column header alignment 
Csharp :: csharp bubble sort 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =