interviews.dotnetthread.com

↑ Grab this Headline Animator

Thursday, November 20, 2008

Whats the use of verbatim character "@" in the .NET?

Verbatim character is one of the feature in C# that prevents the translation of string or identifier, where it is treated "as-is".
To create Verbatim string, we need to prefix it with the verbatim character (@). We can place any type of character in the Verbatim string including escape characters because they are not translated. The output of the string appears as it was written in the string.

The one exception character that is translated in verbatim string is the quote (") that is translated even in the Verbatim string. Verbatim string can contain physical line feed and escape characters too as displayed in the code below.

string verbatim = @"sometext////////// // ///////'//text";

You can see that in the above code snippet single quote will be ignored but if we place the double quote in between the string then the string is terminated there itself.

Using verbatim character we can use the reserved keyword of C# too, however it is not suggested.

string @for = @"sometext////////// // //////////text";

string myString = @for;In the above code, for is the reserved keyword that is used for looping in C#, however if we want to use it we can prefix it with verbatim character and use it. As written earlier this is not a good practice of use reserved keyword so we should avoid it.



We are using @ character in the differenct scenario like

  In the sql server, the input parameters will defind with the help of @ like

    Create procedure Test
    (
    @Firstname
    @Lastname
    )

when we are doing file related opeartion in the c#.net the we are specifying file path as

    string Filename=@"c:\Test\employee.xml"

In the sql server if we are double "@@" before any parameter of procedure then treated as global varible.

Submit this story to DotNetKicks

No comments:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles