Why does this bit of C# code with array initializer not refactor how I expect

70 Views Asked by At

I have the following code;

char[] leadingDot = { '.' };
string trimStart = fileName.TrimStart(leadingDot);

I cannot seem to figure out the syntax to combine it into a single line. ReSharper has no suggestions either.

I completely understand why the following code doesn't work, let alone look right, but I would expect something like:

string trimStart = fileName.TrimStart( { '.' } );

It gives me the same vibe you get when you type var x = null; Ideas?

1

There are 1 best solutions below

1
gabriel.hayes On BEST ANSWER
string trimStart = fileName.TrimStart(new char[] { '.'});