Verbatim string literal in C#
I have a question on Verbatim String in C#. I have just started to use C #. Although I have learnt C, C++ from my college, but C# I am learning on my own. I am finding this quite difficult. I am on the String Literals topic and I am not able to uderstand this topic. And also can anyone explain to me what is a Verbatim string literals in C#. Thank you in advance.
Re: Verbatim string literal in C#
There are two types of String Literals in C sharp they are:
1. String Literals.
2. Verbatim String Literals.
While we declare a String variable there are a few characters which we are not allowed to use. Some of these are ', ", \.
But a solution to this is to use the Verbatim String. A Verbatim string maes use of the @ symbol.
eg.
C:\Program Files\
The above path can be specified as:
Code:
string rooot = @"C:\Program Files\"
Re: Verbatim string literal in C#
I am also learning C Sharp and this is my first programming language experience. C sharp includes a unique string literal named Verbatim string literal. A string literal which had @ sign in the start is called a Verbatim string literal. This 'at sign' defines that within the following " "(quotation mark) there should be no interpretation of chararcter to be done.
Re: Verbatim string literal in C#
I also had similar problem when I started studying C sharp. I was also alot confused with this Verbatim String. In C Sharp a Verbatim String literal includes an @ sign and the string enclosed in "" following the @ sign. Thus, the compiler will not perform any character interpretation on the Verbatim String. Thus allowing the programmer to use those charactrs and symbols which they are not allowed to use. For example, if a programmer wants to print "Good Morning", the programmer can do it in the following manner;
string S = @"Good Morning";