यह जांचने के लिए कि निर्दिष्ट स्ट्रिंग स्ट्रिंगकोलेक्शन में है या नहीं, कोड इस प्रकार है -
उदाहरण
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("Does the specified string is in the StringCollection? = "+stringCol.Contains("800"));
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
Array elements... 100 200 300 400 500 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("Does the specified string is in the StringCollection? = "+stringCol.Contains("Katie"));
}
} आउटपुट
यह निम्नलिखित आउटपुट देगा -
String array elements... John Tim Kevin Bradman Katie Tom Nathan Does the specified string is in the StringCollection? = True