@"string"

  • Thread starter Thread starter Mike Gleason jr Couturier
  • Start date Start date
M

Mike Gleason jr Couturier

Why do I see a @ preceding strings in code examples?

What does the @ do?


thanks!
 
Do you mean for 'parameters' in sql statements?

Can you post an example of what you see?
 
Hello Mike Gleason jr Couturier,
Why do I see a @ preceding strings in code examples?

What does the @ do?

I believe it is a c# sytax that prevents the compiler otherwise interpreting
certain characters as escape codes.

for example
 
Rory Becker said:
Hello Mike Gleason jr Couturier,


I believe it is a c# sytax that prevents the compiler otherwise interpreting
certain characters as escape codes.

for example

Correct and in addition a string preceded with @ can split across lines:-

string someSQL = @"
SELECT a.Field1, a.Field2
FROM ATable a
INNER JOIN BTable b ON b.ID = a.ID
WHERE b.Field3 = 15"

The down side is that " need to be duplicated as "" e.g.:-

string someXML = @"<root thing=""x"" />"
 
Ok thanks guys...

I was seeing the @ when declaring connection strings in books... (web
projetcs, web.config)

Thanks!
 
You should also read up on
"SQL Injections"... just google it up

It will give you good examples of why the @ is used as a parameter.
 
Why do I see a @ preceding strings in code examples?

What does the @ do?

thanks!

with this symbol you could go without escape chars, for example

without @: var str="e:\\folder1\\folder2\\folder3\\file"

with @: var str=@"e:\folder1\folder2\folder3\file"
 
Back
Top