Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> C#

सी # में निर्दिष्ट इंडेक्स से शुरू होने वाले संपूर्ण ऐरेलिस्ट को 1-डी ऐरे में कॉपी करना

निर्दिष्ट अनुक्रमणिका से शुरू होने वाली संपूर्ण ArrayList को 1-D सरणी में कॉपी करने के लिए, कोड इस प्रकार है -

उदाहरण

using System;
using System.Collections;
public class Demo {
   public static void Main(){
      ArrayList list = new ArrayList();
      list.Add("PQ");
      list.Add("RS");
      list.Add("TU");
      list.Add("UV");
      list.Add("WX");
      list.Add("YZ");
      Console.WriteLine("ArrayList elements...");
      for (int i = 0; i < list.Count; i++) {
         Console.WriteLine(list[i]);
      }
      String[] strArr = new String[6] {"One", "Two", "Three", "Four", "Five", "Six"};
      Console.WriteLine("\nArray elements...");
      for (int i = 0; i < strArr.Length; i++) {
         Console.WriteLine(strArr[i]);
      }
      list.CopyTo(strArr, 0);
      Console.WriteLine("\nArray elements (updated)...");
      for (int i = 0; i < strArr.Length; i++) {
         Console.WriteLine(strArr[i]);
      }
   }
}

आउटपुट

यह निम्नलिखित आउटपुट देगा -

ArrayList elements...
PQ
RS
TU
UV
WX
YZ

Array elements...
One
Two
Three
Four
Five
Six

Array elements (updated)...
PQ
RS
TU
UV
WX
YZ

उदाहरण

आइए अब एक और उदाहरण देखें -

using System;
using System.Collections;
public class Demo {
   public static void Main(){
      ArrayList list = new ArrayList();
      list.Add(100);
      list.Add(200);
      Console.WriteLine("ArrayList elements...");
      for (int i = 0; i < list.Count; i++) {
         Console.WriteLine(list[i]);
      }
      int[] intArr = new int[5] {10, 20, 30, 40, 50};
      Console.WriteLine("\nArray elements...");
      for (int i = 0; i < intArr.Length; i++) {
         Console.WriteLine(intArr[i]);
      }
      list.CopyTo(intArr, 0);
      Console.WriteLine("\nArray elements (updated)...");
      for (int i = 0; i < intArr.Length; i++) {
         Console.WriteLine(intArr[i]);
      }
   }
}

आउटपुट

यह निम्नलिखित आउटपुट देगा -

ArrayList elements...
100
200

Array elements...
10
20
30
40
50

Array elements (updated)...
100
200
30
40
50

  1. सी # में ArrayList के अंत में तत्व जोड़ना

    ArrayList के अंत में तत्वों को जोड़ने के लिए, कोड इस प्रकार है - उदाहरण using System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list = new ArrayList();       list.Add("Andy");   &nb

  1. सी # में ArrayList की निर्दिष्ट अनुक्रमणिका पर तत्व निकालें

    ArrayList के निर्दिष्ट सूचकांक में तत्व को हटाने के लिए, कोड इस प्रकार है - उदाहरण using System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("A");

  1. सी # में सॉर्टेडलिस्ट की निर्दिष्ट अनुक्रमणिका से निकालें

    SortedList की निर्दिष्ट अनुक्रमणिका से निकालने के लिए, कोड इस प्रकार है - उदाहरण using System; using System.Collections; public class Demo {    public static void Main(String[] args) {       SortedList sortedList = new SortedList();       sortedList.Add("