Tuesday, June 25, 2013

The @ sign in C#

The @ symbol serves 2 purposes in C#:
#1 allows you to use a reserved keyword as a variable like this:
int @int = 15;
#2 lets you specify a string without having to escape any characters. For instance the '\' character is an escape character so typically you would need to do this:
var myString = "c:\\myfolder\\myfile.txt"
alternatively you can do this:
var myString = @"c:\myFolder\myfile.txt"
Info

No comments:

Post a Comment