c#中@的作用

1.用@可以不用写转义字符。如文件路径,可以不用写两个反斜杠,即忽略转义

2.可以让字符串跨行。

 1 string script = @"
 2         a = 1
 3         b = 'hello world'
 4         c = true
 5 
 6         d = {
 7            f1 = 12, f2 = 34, 
 8            1, 2, 3,
 9            add = function(self, a, b) 
10               print('d.add called')
11               return a + b 
12            end
13         }
14 
15         function e()
16             print('i am e')
17         end
18 
19         function f(a, b)
20             print('a', a, 'b', b)
21             return 1, {f1 = 1024}
22         end
23         
24         function ret_e()
25             print('ret_e called')
26             return e
27         end
28     ";

  如果没有@符号,就会出现下面这种结果。

3.c#中是不允许用关键字作为标识符的,但是在关键字前加上@,就打破了这个界限。@int是可以存在,当做变量的。

原文地址:https://www.cnblogs.com/WhiteTaken/p/6292545.html