Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace list
{
class Program
{
static void Main(string[] args)
{
List<int> car = new List<int>() { 2,8888,77,66,2,1,2,2,2,2,2,22,};
// after
car.Add(999); // add value and indix
car.Remove(8888); // delit to value
car.RemoveAt(2); // delit to indix
foreach (int n in car) // loop
{
Console.WriteLine(n);
}
List<int> list = new List<int>(new int[] { 2, 3, 7 });
// Loop with for and use string interpolation to print values.
for (int i = 0; i < list.Count; i++)
{
Console.WriteLine($"{i} = {list[i]}");
}
// test code
Console.WriteLine(car[1]); // write one indix
Console.WriteLine(car.Count); // write list length
Console.ReadKey();
}
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more