In this IronPython example what is the @ symbol doing and how is it implemented?
http://www.ironpython.info/index.php/Using_Python_Classes_from_.NET/CSharp_IP_2.6
string code = @"
print 'test = ' + test
class MyClass:
def __init__(self):
pass
def somemethod(self):
print 'in some m开发者_Go百科ethod'
def isodd(self, n):
return 1 == n % 2
";
Is that '@' part of C# or is that something added by IronPython? If the latter, how do you do that in C#, some kind of operator overloading (basically could I then make '@' do whatever I want, etc)? Example implementation would be great. Otherwise, what's going on here?
@""
is a verbatim string literal in C#. That is, escape characters inside it are not interpreted.
In this case, the python code is being stored in the C# code
string variable, and then is compiled into a CompiledCode
from a ScriptSource
using a ScriptEngine
(which is itself created using Python.CreateEngine()
).
The @ is part of the C# code. It means that the string is a verbatim string literal. The string holds the Python code to be executed.
string path = @"C:\Sweet\now\I\can\use\backslashes\without\writing\them\all\twice.txt"
精彩评论