سلام خدمت کاربران وب سایت پروگرم 98 😉 در این مطلب از وب سایت پروگرم 98 کد نمایش تعداد عناصر Generic List در سی شارپ #C را آماده کردم. امیدوارم که این کد برای شما مفید باشد.
خروجی پروژه:
Initial number of elements: 0
Adding 6 elements
Number of elements: 6
Adding 20 more elements
Current capacity: 32
Number of elements after adding 20: 26
Contents: C A E B D F a b c d e f g h i j k l m n o p q r s t
Adding 6 elements
Number of elements: 6
Adding 20 more elements
Current capacity: 32
Number of elements after adding 20: 26
Contents: C A E B D F a b c d e f g h i j k l m n o p q r s t
کد نمایش تعداد عناصر Generic List در سی شارپ #C :
using System;
using System.Collections.Generic;
class MainClass {
public static void Main() {
List<char> lst = new List<char>();
Console.WriteLine("Initial number of elements: " +
lst.Count);
Console.WriteLine();
Console.WriteLine("Adding 6 elements");
lst.Add('C');
lst.Add('A');
lst.Add('E');
lst.Add('B');
lst.Add('D');
lst.Add('F');
Console.WriteLine("Number of elements: " +
lst.Count);
Console.WriteLine("Adding 20 more elements");
using System.Collections.Generic;
class MainClass {
public static void Main() {
List<char> lst = new List<char>();
Console.WriteLine("Initial number of elements: " +
lst.Count);
Console.WriteLine();
Console.WriteLine("Adding 6 elements");
lst.Add('C');
lst.Add('A');
lst.Add('E');
lst.Add('B');
lst.Add('D');
lst.Add('F');
Console.WriteLine("Number of elements: " +
lst.Count);
Console.WriteLine("Adding 20 more elements");