What's the meaning of "|" and "@" in C#?
-
Dear All: Could anyone give me some useful articles about introducing the symbol "|" and "@" in C# please? For example, I saw a code something like:
FileSystemWatcher fsm = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
fsm.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
Thanks
Asura
-
Dear All: Could anyone give me some useful articles about introducing the symbol "|" and "@" in C# please? For example, I saw a code something like:
FileSystemWatcher fsm = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
fsm.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
Thanks
Asura
-
Dear All: Could anyone give me some useful articles about introducing the symbol "|" and "@" in C# please? For example, I saw a code something like:
FileSystemWatcher fsm = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
fsm.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
Thanks
Asura
I think this two characters have nothing in common.
Ming Luo wrote:
"@"
Is called a verbatim. Use of Verbatim[^] and
Ming Luo wrote:
"|"
is a logical operator: http://en.wikibooks.org/wiki/C_Sharp_Programming/Operators[^]
Wamuti: Any man can be an island, but islands to need water around them! Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
-
Dear All: Could anyone give me some useful articles about introducing the symbol "|" and "@" in C# please? For example, I saw a code something like:
FileSystemWatcher fsm = new FileSystemWatcher(Environment.GetEnvironmentVariable("USERPROFILE"));
fsm.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite;
Thanks
Asura
-
'|' is logical "OR' operator. '@' is used with strings to avoid escape characters. you can use like @"c:\hello.cs" ; instead of adding escape character for '\\'
cooljeba1 wrote:
'|' is logical "OR' operator.
'|' is bitwise 'OR' operator for integers (also logical 'OR' operator for booleans) '||' is logical 'OR' operator for booleans :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]