LoginSignup
12
14

More than 5 years have passed since last update.

C#の文字列の先頭に@をつける意味。

Posted at

初めてのC#に戸惑いながら勉強しています。

何となく斬新だと思ったことです。
文字列の先頭に「@」をつけるとエスケープしなくてよくなるっていう話。

例えばファイルパスとして
C:\Windows\System32\drivers\etc\hosts
みたいなパスを指定するときに

string str = "C:\\Windows\\System32\\drivers\\etc\\hosts";

というように書きたい気分なんですが、

string str = @"C:\Windows\System32\drivers\etc\hosts";

というように文字列の前に@を書けばエスケープ不要というもの。
CやC++もほとんどやったことないんですが、同じようにできるのかな?

12
14
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14