Click to See Complete Forum and Search --> : query about connection string in c#.net


vrathaure
11-07-2006, 04:46 AM
This is the code from C# in .net

1. how are the below 2 codes different :-

i) string connectionString ="data source=myserver;user id=myusername;password=mypassword;";

ii) string connectionString = @"server = myserver;uid = myusername;password = mypassword;";


2. and plz explain me the meaning of "@" in the ii) part.


thanks and regards,
vr

sirpelidor
11-07-2006, 10:23 AM
(i) is regular string literal; it consists of zero or more characters enclosed in double quotes (i.e: "yo!")

(ii) is a verbatim string literal; it consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character (i.e: @"yo!")

the "yo" was a bad example, but consider you want to print a double quote in your string like this: yo"


you can't do it with regular string literal because the double quote will treat as "closing double-quote".

in order to print: yo", you need to:

@"yo"""

detail is here (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_2_4_4_5.asp)

vrathaure
11-07-2006, 10:59 PM
thanks
vr