एक सरणी सेट करें -
int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70;
अब एक सूची सेट करें और उसमें सरणी जोड़ें -
List<int> myList = new List<int>(val);
निम्नलिखित कोड है -
उदाहरण
using System; using System.Collections.Generic; public class Demo { public static void Main() { int[] val = new int[5]; // integer elements val[0] = 15; val[1] = 25; val[2] = 40; val[3] = 58; val[4] = 70; List<int> myList = new List<int>(val); Console.WriteLine("Elements..."); foreach(int res in myList) { Console.WriteLine(res); } // count integer elements Console.WriteLine("Number of elements: "+myList.Count); } }
आउटपुट
Elements... 15 25 40 58 70 Number of elements: 5