I basically want to type in a string[] and and be able to do a foreach based on newline. I tried like this but I dont believe this works.
static string[] mystrings = {"here"+
"there"+
"mine"
}
and I want to foreach it and get back one at a time. Is this possible?
You just have to add
new[]ornew string[]in front of the curly-brace list. And use commas, not plus signs. As inFYI, the
new[]shortcut is syntactic sugar provided by C#, which infers that you specifically meannew string[]. If you are creating an array of mixed types (such as an array ofobject), you will have to explicitly usenew object[], because otherwise the C# compiler won’t know which type you are implying. That is: