![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Using @ Sign at String Variables? Hi, one of my colleagues has written something like the following code in C#: string a = @ConfigurationManager.AppSettings["MyTempPath"]; Is the @ sign of any use here? Or is it just the compiler not giving an error because it's basically a string that's being attached to the @ sign? Thanks for enlightening me! Regards, www.axeldahmen.de Axel Dahmen |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Using @ Sign at String Variables? Axel, The @ operator is of no use here. @ has two significant uses in C#: 1) Hard-coded string literals, which start with @ do not have their escape sequences processed. For example, this allows you to avoid escaping file paths (@"C:\folder\path.txt" vs "C:\\folder\\path.txt") but the disadvantage is that you can't use any escape sequences such as \n (new line) or \r (carriage return). 2) @ can be used for variable names shared with such C# keywords as 'new', 'class', etc. e.g. string class = "test"; // Identifier expected, 'class' is keyword string @class = "test"; // OK HTH, -- Stanimir Stoyanov Microsoft MVP -- Visual C# http://stoyanoff.info "Axel Dahmen" <keentoknow@xxxxxx> wrote in message news:%23SvbX5K1JHA.1644@xxxxxx Hi, one of my colleagues has written something like the following code in C#: string a = @ConfigurationManager.AppSettings["MyTempPath"]; Is the @ sign of any use here? Or is it just the compiler not giving an error because it's basically a string that's being attached to the @ sign? Thanks for enlightening me! Regards, www.axeldahmen.de Axel Dahmen |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Using @ Sign at String Variables? Hi, Stanimir, great, thanks. So there is no use for it with string variables, as I thought. That variable name behaviour was new to me. Thanks for enlighten me on this one! Best regards, www.axeldahmen.de Axel Dahemn --------- "Stanimir Stoyanov (C# MVP)" <stoyanov@xxxxxx> schrieb im Newsbeitrag news:%23XT15YM1JHA.4288@xxxxxx Quote: > Axel, > > The @ operator is of no use here. @ has two significant uses in C#: > > 1) Hard-coded string literals, which start with @ do not have their escape > sequences processed. For example, this allows you to avoid escaping file > paths (@"C:\folder\path.txt" vs "C:\\folder\\path.txt") but the disadvantage > is that you can't use any escape sequences such as \n (new line) or \r > (carriage return). > > 2) @ can be used for variable names shared with such C# keywords as 'new', > 'class', etc. e.g. > > string class = "test"; // Identifier expected, 'class' is keyword > string @class = "test"; // OK > > HTH, > -- > Stanimir Stoyanov > Microsoft MVP -- Visual C# > > http://stoyanoff.info > "Axel Dahmen" <keentoknow@xxxxxx> wrote in message > news:%23SvbX5K1JHA.1644@xxxxxx > Hi, > > one of my colleagues has written something like the following code in C#: > > string a = @ConfigurationManager.AppSettings["MyTempPath"]; > > Is the @ sign of any use here? > > Or is it just the compiler not giving an error because it's basically a > string that's being attached to the @ sign? > > Thanks for enlightening me! > > Regards, > www.axeldahmen.de > Axel Dahmen > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Using @ Sign at String Variables? Hi Axel, In addition to Stanimir's second point, here I quote the C# 3.0 specification 2.4.2 in case you and other community members who are interested: The prefix "@" enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier. Use of the @ prefix for identifiers that are not keywords is permitted, but strongly discouraged as a matter of style. The example: class @class { public static void @static(bool @bool) { if (@bool) System.Console.WriteLine("true"); else System.Console.WriteLine("false"); } } class Class1 { static void M() { cl\u0061ss.st\u0061tic(true); } } defines a class named "class" with a static method named "static" that takes a parameter named "bool". Note that since Unicode escapes are not permitted in keywords, the token "cl\u0061ss" is an identifier, and is the same identifier as "@class". Two identifiers are considered the same if they are identical after the following transformations are applied, in order: " The prefix "@", if used, is removed. " Each unicode-escape-sequence is transformed into its corresponding Unicode character. " Any formatting-characters are removed. The C# Language Specification Version 3.0 can be downloaded here: http://download.microsoft.com/downlo...6-b2a8-75351c6 69b09/CSharp%20Language%20Specification.doc Best regards, Jie Wang (jiewan@xxxxxx, remove 'online.') Microsoft Online Community Support Delighting our customers is our #1 priority. We welcome your comments and suggestions about how we can improve the support we provide to you. Please feel free to let my manager know what you think of the level of service provided. You can send feedback directly to my manager at: msdnmg@xxxxxx. ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/en-us/subs...#notifications. Note: MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 2 business days is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/en-us/subs.../aa948874.aspx ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| question about auto-expanding variables in a string | PowerShell | |||
| Capture elements of a string into variables | VB Script | |||
| Re: best way to break string into variables | PowerShell | |||
| SQL insert string with variables in foreach | PowerShell | |||