From: Mike Gleason jr Couturier on
Why do I see a @ preceding strings in code examples?

What does the @ do?


thanks!


From: Miro on
Do you mean for 'parameters' in sql statements?

Can you post an example of what you see?


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

From: Rory Becker on
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


From: Anthony Jones on
"Rory Becker" <rorybecker(a)newsgroup.nospam> wrote in message
news:3af1034718d0c8caaf282538db6d(a)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


From: Jon Skeet [C# MVP] on
Mike Gleason jr Couturier <nospam(a)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(a)pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com