`@`在C#中的字符串开头是什么意思?考虑以下行:readonlyprivatestringTARGET_BTN_IMG_URL=@"\ad1-sunglimTest";在这一行中,为什么需要附加@?它代表文字字符串,其中''字符不代表转义序列。@告诉C#将其视为文字字符串逐字字符串文字。例如:strings="C:WindowsMyfile.txt";是一个错误,因为W和M不是有效的转义序列。你需要这样写:strings="C:\Windows\Myfile.txt";为了更清楚,您可以使用无法识别为特殊字符的文字字符串。所以:strings=@"C:WindowsMyfile.txt";完全没问题。编辑:MSDN提供了以下示例:stringa="hello,world";//你好,世界stringb=@"hello,world";//你好,世界stringc="hellotworld";//你好世界字符串d=@"hellotworld";//hellotworldstringe="Joesaid"Hello"tome";//Joesaid"Hello"tomestringf=@"Joesaid""Hello""tome";//Joe对我说“你好”stringg="\\server\share\file.txt";//\serversharefile.txt字符串h=@"\serversharefile.txt";//\serversharefile.txt字符串i="onerntwornthree";stringj=@"一二三";因为您的字符串包含转义序列“”。为了告诉编译器不要将“”视为转义序列,您必须使用“@”。以上是C#学习教程:C#中字符串开头的`@`是什么意思?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
