ArrayList全体をC#の1次元配列にコピーするにはどうすればよいですか?
ArrayList全体を1次元配列にコピーするには、コードは次のとおりです-
例
using System;
using System.Collections;
public class Demo {
public static void Main(){
ArrayList list = new ArrayList();
list.Add("AB");
list.Add("BC");
list.Add("CD");
list.Add("EF");
list.Add("GH");
list.Add("IJ");
list.Add("KL");
list.Add("MN");
String[] strArr = new String[10];
Console.WriteLine("ArrayList...");
foreach(Object obj in list)
Console.WriteLine("{0}", obj);
list.CopyTo(strArr);
Console.WriteLine("\nString Array after copying elements from ArrayList...");
foreach(Object ob in strArr)
Console.WriteLine("{0}", ob);
}
} 出力
これにより、次の出力が生成されます-
ArrayList... AB BC CD EF GH IJ KL MN String Array after copying elements from ArrayList... AB BC CD EF GH IJ KL MN
例
別の例を見てみましょう-
using System;
using System.Collections;
public class Demo {
public static void Main(){
ArrayList list = new ArrayList();
list.Add(100);
list.Add(200);
list.Add(300);
list.Add(400);
list.Add(500);
list.Add(600);
list.Add(700);
list.Add(800);
list.Add(900);
list.Add(1000);
int[] intArr = new int[10];
Console.WriteLine("ArrayList...");
foreach(Object obj in list)
Console.WriteLine("{0}", obj);
list.CopyTo(intArr);
Console.WriteLine("\nInteger Array after copying elements from ArrayList...");
foreach(Object ob in intArr)
Console.WriteLine("{0}", ob);
}
} 出力
これにより、次の出力が生成されます-
ArrayList... 100 200 300 400 500 600 700 800 900 1000 Integer Array after copying elements from ArrayList... 100 200 300 400 500 600 700 800 900 1000
-
MongoDBの配列の先頭に値を追加するにはどうすればよいですか?
MongoDBの配列の先頭に値を追加するには、unshift()-を使用できます。 yourArrayName.unshift("yourValue"); 上記の構文は、MongoDBの配列の先頭に値を追加します。まず、文字列の配列を作成しましょう- > technicalSkills=["Java","MySQL","C","SQL SERVER","ORACLE","PL/SQL"]; これにより、次の出力が生成されます- [ "J
-
C#でディレクトリの内容全体をコピーするにはどうすればよいですか?
ディレクトリの内容全体をコピーするときは、そのサブディレクトリと関連ファイルをコピーすることがより重要です。 例 以下のようなサブディレクトリとファイルを持つデモソースディレクトリを考えてみましょう。 以下は、最初は空のデモターゲットディレクトリです。 using System; using System.IO; namespace DemoApplication { class Program { public static void Main() { &nbs