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

What does the @ do?


thanks!

Re: @"string" by Miro

Miro
Tue Jul 08 09:21:16 CDT 2008

Do you mean for 'parameters' in sql statements?

Can you post an example of what you see?


"Mike Gleason jr Couturier" <nospam@invalidhost.com> wrote in message
news:urljRJQ4IHA.3500@TK2MSFTNGP05.phx.gbl...
> Why do I see a @ preceding strings in code examples?
>
> What does the @ do?
>
>
> thanks!
>


Re: @"string" by Rory

Rory
Tue Jul 08 09:40:55 CDT 2008

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
-------------------------------------------------------------
string SomeString = "\n"; //This produces an enter keystroke
string OtherString = @"\n"; //This produces a string containing the backslash
and 'n' characters.
-------------------------------------------------------------


--
Rory



Re: @"string" by Anthony

Anthony
Tue Jul 08 10:17:44 CDT 2008

"Rory Becker" <rorybecker@newsgroup.nospam> wrote in message
news:3af1034718d0c8caaf282538db6d@news.microsoft.com...
> 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
> -------------------------------------------------------------
> string SomeString = "\n"; //This produces an enter keystroke
> string OtherString = @"\n"; //This produces a string containing the
backslash
> and 'n' characters.
> -------------------------------------------------------------
>

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"" />"





--
Anthony Jones - MVP ASP/ASP.NET



Re: @"string" by Jon

Jon
Tue Jul 08 12:51:50 CDT 2008

Mike Gleason jr Couturier <nospam@invalidhost.com> wrote:
> Why do I see a @ preceding strings in code examples?
>
> What does the @ do?

See http://pobox.com/~skeet/csharp/strings.html

--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com

Re: @"string" by Mike

Mike
Tue Jul 08 12:53:21 CDT 2008

Ok thanks guys...

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

Thanks!



Re: @"string" by Miro

Miro
Tue Jul 08 14:04:46 CDT 2008

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.


"Mike Gleason jr Couturier" <nospam@invalidhost.com> wrote in message
news:OL51DOS4IHA.1196@TK2MSFTNGP05.phx.gbl...
> Ok thanks guys...
>
> I was seeing the @ when declaring connection strings in books... (web
> projetcs, web.config)
>
> Thanks!
>


Re: @"string" by Garfilone

Garfilone
Wed Jul 09 02:18:11 CDT 2008

On Jul 8, 9:55=A0pm, "Mike Gleason jr Couturier"
<nos...@invalidhost.com> wrote:
> 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=3D"e:\\folder1\\folder2\\folder3\\file"

with @: var str=3D@"e:\folder1\folder2\folder3\file"