Thursday, November 20, 2008
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
when we are doing file related opeartion in the c#.net the we are specifying file path as
In the sql server if we are double "@@" before any parameter of procedure then treated as global varible.
Also Read other Top Articles
- JSON Serialization in VS 2008
- Implementing Forms Authentication in Silverlight Application.
- Making GridView Rows or Individual Cells Clickable and Selectable.
- Enabling browser back button for GridView Paging and Sorting in Ajax 1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008)
- How to pass values from User Control to Page or calling Page methods from User Control.
- What is WCF?
- New features in C# 4.0
- C# to VB.NET and VB.NET to C# online free converter tools.