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

2 comments :

  1. Componentbuy is one of the fastest growing distributors of Semiconductors and electronic Components in the world.Supports more than 20 Millions of Electronic components sourcing needs with Engineering Data support. Locating all your required components for your design and production needs.
    Our website will act as tool for the sourcing and Design engineers on the components needs.
    componentbuy.com

    ReplyDelete