Some functions in my class library accepts string[]
as parameter.
I want to convert my System.Collections.Specialized.StringCollection
to string[]
.
Is it possible with some one liner or I have to create array with loop?
Use StringCollection.CopyTo(string[],index) to copy the contents to string array. This is supported in all .Net frameworks.
System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();
sc.Add("Test");
sc.Add("Test2");
string[] strArray = new string[sc.Count];
sc.CopyTo(strArray,0);
Try this
System.Collections.Specialized.StringCollection strs = new System.Collections.Specialized.StringCollection();
strs.Add("blah");
strs.Add("blah");
strs.Add("blah");
string[] strArr = strs.Cast<string>().ToArray<string>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With