How do I get a new array from the second element in c #?


I originally had this code which I mistakenly thought would do what I wanted it to:

string firstArg = args[0];
string[] otherArgs = args.Except(new string[] { args[0] }).ToArray();

However, it seems that the .Except method removes duplicates. So if I was to pass through the arguments a b c c, the result of otherArgs would be b c not b c c.

So how can I get a new array with all the elements from the second element onwards?

Use the Skip method:

var otherArgs = args.Skip(1).ToArray();