473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

@"string"

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

What does the @ do?
thanks!
Jul 8 '08 #1
7 1012
Do you mean for 'parameters' in sql statements?

Can you post an example of what you see?
"Mike Gleason jr Couturier" <no****@invalidhost.comwrote in message
news:ur**************@TK2MSFTNGP05.phx.gbl...
Why do I see a @ preceding strings in code examples?

What does the @ do?
thanks!
Jul 8 '08 #2
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
Jul 8 '08 #3
"Rory Becker" <ro********@newsgroup.nospamwrote in message
news:3a**************************@news.microsoft.c om...
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
Jul 8 '08 #4
Mike Gleason jr Couturier <no****@invalidhost.comwrote:
Why do I see a @ preceding strings in code examples?

What does the @ do?
See http://pobox.com/~skeet/csharp/strings.html

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 8 '08 #5
Ok thanks guys...

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

Thanks!
Jul 8 '08 #6
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" <no****@invalidhost.comwrote in message
news:OL**************@TK2MSFTNGP05.phx.gbl...
Ok thanks guys...

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

Thanks!
Jul 8 '08 #7
On Jul 8, 9:55*pm, "Mike Gleason jr Couturier"
<nos...@invalidhost.comwrote:
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"
Jul 9 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.