Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# list

List<string> myListOfStrings = new List<string> 
{
	"this",
	"is",
	"my",
	"list"
};
Comment

c# list

using System.Collections.Generic;

private List<string> list;  //creates list named list of type string

list.Add(string); //adds string at last index of list
list.Count;  //get length of list
list.Insert(2,"pos 2");  // Insert string "pos 2" in position 2
list[i];  //get item from index i
Comment

c# list

// This will create a new list called 'nameOfList':
var nameOfList = new List<string> 
{
  "value1",
  "value2",
  "value3"
};
Comment

C# lists

// List with default capacity  
List<Int16> list = new List<Int16>();  
// List with capacity = 5  
List<string> authors = new List<string>(5);  
string[] animals = { "Cow", "Camel", "Elephant" };  
List<string> animalsList = new List<string>(animals); 
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

C Sharp List

using System;  
using System.Collections.Generic;  
 
public class Example  
{  
    public static void Main(string[] args)  
    {  
        // Create a list of strings  
        var countries = new List<string>();  
        countries.Add("India");  
        countries.Add("Australia");  
        countries.Add("Japan");  
        countries.Add("Canada");  
        countries.Add("Mexico");  
 
        // Iterate list element using foreach loop  
        foreach (var country in countries)  
        {  
            Console.WriteLine(country);  
        }  
    }  
}
Comment

list C#

List<string> names = new List<string>();List<Object> someObjects = new List<Object>();
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# faker 
Csharp :: c# datagridview change column alignment 
Csharp :: remove all values from list c# 
Csharp :: how to convert int to string c# 
Csharp :: Get replace normal text from word document in C# 
Csharp :: C# Async Function without await 
Csharp :: c# datetime 
Csharp :: c# catch two exceptions in one block 
Csharp :: c# list to observablecollection 
Csharp :: c# getting response content from post 
Csharp :: inheritance in c# 
Csharp :: how to configure visual studio for unity 
Csharp :: datatable select c# 
Csharp :: c# sort llist 
Csharp :: binary tree c# 
Csharp :: dateTime first/last 
Csharp :: logical operators in c# 
Csharp :: csharp attributes as generics constraints 
Csharp :: how to make a C# game launcher 
Csharp :: how to c# 
Csharp :: c# Prefix Sum of Matrix (Or 2D Array) 
Csharp :: Handling Collisions unity 
Csharp :: Photon Register Callbacks 
Csharp :: how to get angular on visual studio mac 
Csharp :: what is implicit keyword c# 
Csharp :: prevent C# app from lingering after closing in background processes 
Csharp :: Custom Encrypted String Type 
Csharp :: convert string csv line to list c# 
Csharp :: how do I write to a csv file from c# using entity framework 
Csharp :: dateTime to dataRow in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =