What is StringCollection?

 Posted by SheoNarayan on 4/17/2008 | Category: .NET Framework Interview questions | Views: 8996
Answer:

StringCollection is a simple resizable collection of strings

Following function shows how to insert and retrive data into/from StringCollection.

public static string GetStringCollection()

{
System.Text.StringBuilder strB = new System.Text.StringBuilder();
// Add strings into StringCollection
System.Collections.Specialized.StringCollection strC = new System.Collections.Specialized.StringCollection();
strC.Add("Ram 1");
strC.Add("Ram 2");
strC.Add("Ram 3");
strC.Add("Ram 4");
strC.Add("Ram 5");

// Retrieve string from StringCollection
System.Collections.Specialized.StringEnumerator coll = strC.GetEnumerator();
while (coll.MoveNext())
{
strB.Append(coll.Current + "
");
}
return strB.ToString();
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response