StringCollectionがC#で読み取り専用かどうかを確認します
StringCollectionが読み取り専用かどうかを確認するためのコードは、次のとおりです-
例
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection stringCol = new StringCollection();
String[] arr = new String[] { "100", "200", "300", "400", "500" };
Console.WriteLine("Array elements...");
foreach (string res in arr) {
Console.WriteLine(res);
}
stringCol.AddRange(arr);
Console.WriteLine("Is the StringCollection read-only? = "+stringCol.IsReadOnly);
Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));
}
} 出力
これにより、次の出力が生成されます-
Array elements... 100 200 300 400 500 Is the StringCollection read-only? = False Does the specified string is in the StringCollection? = False
例
別の例を見てみましょう-
using System;
using System.Collections.Specialized;
public class Demo {
public static void Main() {
StringCollection stringCol = new StringCollection();
String[] arr = new String[] { "John", "Tim", "Kevin", "Bradman", "Katie", "Tom", "Nathan" };
Console.WriteLine("String array elements...");
foreach (string res in arr) {
Console.WriteLine(res);
}
stringCol.AddRange(arr);
Console.WriteLine("Is the StringCollection read-only? = "+stringCol.IsReadOnly);
Console.WriteLine("Does the specified string is in the StringCollection? = "+stringCol.Contains("Tim"));
}
} 出力
これにより、次の出力が生成されます-
String array elements... John Tim Kevin Bradman Katie Tom Nathan Is the StringCollection read-only? = False Does the specified string is in the StringCollection? = True
-
C#を使用してファイルの存在を確認するにはどうすればよいですか?
次のファイルを見つける必要があるとしましょう- E:\new.txt 上記のファイルの存在を確認するには、Exists()メソッド-を使用します。 if (File.Exists(@"E:\new.txt")) { Console.WriteLine("File exists..."); } ファイルの存在を確認するための完全なコードは次のとおりです- 例 using System; using System.IO; public class Demo { public static void M
-
配列がPythonで美しいかどうかを確認します
一意の要素の配列numsがあるとします。これらの条件が満たされているかどうかを確認する必要があります: 要素は1からnの範囲になります。 配列を昇順で並べ替えてはなりません。 したがって、入力がnums =[2,6,1,5,3,4]のような場合、出力はTrueになります。 これを解決するには、次の手順に従います- n:=numsのサイズ 合計:=nums [0] is_sorted:=True 1からn-1の範囲のiの場合、do nums[i]がnums[i-1]と同じ場合、 Falseを返す nums [i]