FIrstly, this line is a bit ... overcomplicated:
varname = ("0").Split(new string[] { "," }, StringSplitOptions.None);
You can get the same result with
varname = "0".Split(",", StringSplitOptions.None);
or
varname = "0".Split(',', StringSplitOptions.None);
or even
varname = "0".Split(',');
In fact, with a fixed string of
"0"
to
Split
on commas, what you get as a result is always going to be an array of strings containing a single element:
"0"
But this code isn't what you want at all if you want a string in
varname
:
IEnumerable<string> varname = myString.Split(myDelimiter);
Because while a
string
is an
IEnumerable
, it's an
IEnumerable<char>
not an
IEnumerable<string>
If you write this:
foreach (var x in "hello world!")
...
Then the type of
x
inside the loop will be
char
.
So you need to think about exactly what you expect the code to do, because in it's current state, it doesn't make any real sense at all!