Wednesday 27 July 2016

Two little functions i love about c#

The @ symbol


This is so useful and allows you to spread a string over several lines , preserving the control characters such as \ , CR \ LF etc.
example:

string @test ="\this
line2
line3
line4";

will create a four line string that will be preserved as
\this
line2
line3
line4


Path.combine


This takes a string array of parameters and returns a combined path . This is super useful when you dont know if a string has a slash at the end
example:

string[] x = { @"c:\test\",@"frog\" ,"fname.txt" };
System.Console.WriteLine(Path.Combine(x));


would write out :
c:\test\frog\fname.txt