Tags :


Community Content

bugout429
Verbatim String Literals

An easily overlooked feature of the String in C# is the Verbatim String Literal. By prefixing a string literal with "@", you can insert line breaks and other special characters into a string, and the C# compiler will interpret everything between the open and closing quotation marks as the contents of that string. Note that quotation marks within the string need to be doubled, or else the compiler will assume it has hit the end of the string literal.

Example:

string script = @"<script language='javascript'>
 function SelectedValue(selectBox, valueToSelect)
 {
  if (selectBox.options.length > 0)
  {
   for (var i = 0; i < selectBox.options.length; i++)
   {
    var currentOpt = selectBox.options[i];
    if (currentOpt.value == valueToSelect)
    {
     selectBox.selectedIndex = i;
     alert(""Found a match!"");
     break;
    }
   }
  }
 }
 </script>";

 

Tags :

Page view tracker