Click imaginationhunt.blogspot to see latest Blogs.
In our previous blog we have discuss the Escape sequences.
And now we are going to discuss the Verbatim Literals.
VERBATIM LITERALS
We'll tell about verbatim literals but before that let's just recall what we have studied in escape sequences.
Let understand this by an example
using System;
namespace AspnetSolutions
{
class stringEscapeSequences
{
public static void Main()
{
Console.WriteLine("C:\ABC\DEF\GHI\JKL\MNO\PQR\STU");
}
}
}
namespace AspnetSolutions
{
class stringEscapeSequences
{
public static void Main()
{
Console.WriteLine("C:\ABC\DEF\GHI\JKL\MNO\PQR\STU");
}
}
}
If you run the program now. You will find that the string doesn't look like a valid window path. Because single (\) slash cause ERROR: Unrecognized escape sequences. So, to remove this error we put (\\) in place of (\) slash. To make our program error free.
using System;
namespace AspnetSolutions
{
class stringEscapeSequences
{
public static void Main()
{
Console.WriteLine("C:\\ABC\\DEF\\GHI\\JKL\\MNO\\PQR\\STU");
namespace AspnetSolutions
{
class stringEscapeSequences
{
public static void Main()
{
Console.WriteLine("C:\\ABC\\DEF\\GHI\\JKL\\MNO\\PQR\\STU");
}
}
}
}
}
And the moment you do that and run the program. Now, we get our output as we expected. We get out window path printed.
But, can this string seem to look like readable. Let me make you more clearly on this. Suppose we have a string like this.
using System;
namespace AspnetSolutions
{
class stringEscapeSequences
{
public static void Main()
{
Console.WriteLine("C:\\ABC\\DEF\\GHI\\JKL\\MNO\\PQR\\STU\\VWX\\XYZ\\ASD\\ESDF\\DASF\\ASD\\ASD\\ASD\\ASD\\ASD\\ASD\\ADS\\ADS\\ADS\\ASD\\ASD\\DFG\\BFD\\");
namespace AspnetSolutions
{
class stringEscapeSequences
{
public static void Main()
{
Console.WriteLine("C:\\ABC\\DEF\\GHI\\JKL\\MNO\\PQR\\STU\\VWX\\XYZ\\ASD\\ESDF\\DASF\\ASD\\ASD\\ASD\\ASD\\ASD\\ASD\\ADS\\ADS\\ADS\\ASD\\ASD\\DFG\\BFD\\");
}
}
}
}
}
Now,
is this seems to be readable. And what a hard task to put (\\) in place
of every (\) backslash to make our program error free.
So, to solve these problems we use Verbatim String Literals.
So, to solve these problems we use Verbatim String Literals.
Related Questions:
Q-1 Verbatim literals are better used for?
A) Convenience and better readability of strings text consist of backslash characters.
B) Used to initialize multiline strings
C) To apply a quotation mark by using double quotations marks inside a verbatim string
D) All the above.
E) None of the above
Ans- Option (D).
Click imaginationhunt.blogspot to see latest Blogs.
No comments:
Post a Comment