473,324 Members | 2,400 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,324 software developers and data experts.

At or @ usage

I'm new to C#. What's the purpose of the @ ??? I can't find it
indexed in my few C# books. It seems to have something to do with
reading strings literally. That's just a guess. I notice if I place
it outside a path that is in quotes, I don't need the extra backslash.
For Example:

string stagger=@"c:\noteq.cmd";

is the same as

string stagger="c:\\noteq.cmd";

string stagger="c:\noteq.cmd";

without the @ gives an error.
Aug 7 '08 #1
6 1135
folderann wrote:
I'm new to C#. What's the purpose of the @ ??? I can't find it
indexed in my few C# books. It seems to have something to do with
reading strings literally. That's just a guess. I notice if I place
it outside a path that is in quotes, I don't need the extra backslash.
For Example:

string stagger=@"c:\noteq.cmd";

is the same as

string stagger="c:\\noteq.cmd";

string stagger="c:\noteq.cmd";

without the @ gives an error.
In this context @ means that \ is not escape character.

So you avoid writing the two backslashes to get one.

(you put a " in the text by doubling and you can have literal
newlines in the string also)

Arne
Aug 7 '08 #2
On Wed, 06 Aug 2008 22:42:05 -0400, folderann wrote:
I'm new to C#. What's the purpose of the @ ??? I can't find it indexed
http://msdn.microsoft.com/en-us/libr...90(VS.71).aspx

verbatim-string-literal:
@" verbatim -string-literal-charactersopt "

It removes the significance of the \ character, eg \n is a new line, \t
is a tab.
Aug 7 '08 #3
Just for completeness (from the post title, not the example given),
note that an @ prefix is also used (separately) to allow you to use an
otherwise reserved word (/keyword) as a regular name in C#. This is
usually only used when dealing with cross-language issues (different
languages have different keywords) - for example, you can refer to a
member/type/variable @default, when without the @ it would get
interpreted as a language keyword.

Marc
Aug 7 '08 #4
I use it to create long strings such as SQL queries.
Rather than concatenating the string together (at high cost) you can
use the @ to create a multi-line string.

string query = "SELECT * "
+ "FROM RandomTable";
or

string query = @"SELECT *
FROM RandomTable ";
Aug 7 '08 #5
On Aug 7, 3:06*pm, "cfps.Christian" <ge0193...@otc.eduwrote:
I use it to create long strings such as SQL queries.
Rather than concatenating the string together (at high cost) you can
use the @ to create a multi-line string.

string query = "SELECT * "
* * *+ "FROM RandomTable";
or

string query = @"SELECT *
* * *FROM RandomTable ";
There is no execution time cost to doing this in the first form. So
long as the strings are constant, they are concatenated by the
compiler rather than at execution time.
Even if it were performed at execution time, the cost of concatenating
strings is going to be just noise compared with the cost of actually
executing the query and waiting for the results.

Now there's a reasonable argument that the second form is easier to
edit etc, and that's all fine - but the performance argument is a
nonstarter.

Jon
Aug 7 '08 #6
A belated thanks to all. It was very enlightening. I deduced that
the @ took care of the identification of the escape sequence, but I
didn't understand any of it's other uses.

Thanks to all again. I got wrapped up in an other problema and forgot
about this post.

On Thu, 7 Aug 2008 07:15:47 -0700 (PDT), "Jon Skeet [C# MVP]"
<sk***@pobox.comwrote:
>On Aug 7, 3:06Êpm, "cfps.Christian" <ge0193...@otc.eduwrote:
>I use it to create long strings such as SQL queries.
Rather than concatenating the string together (at high cost) you can
use the @ to create a multi-line string.

string query = "SELECT * "
Ê Ê Ê+ "FROM RandomTable";
or

string query = @"SELECT *
Ê Ê ÊFROM RandomTable ";

There is no execution time cost to doing this in the first form. So
long as the strings are constant, they are concatenated by the
compiler rather than at execution time.
Even if it were performed at execution time, the cost of concatenating
strings is going to be just noise compared with the cost of actually
executing the query and waiting for the results.

Now there's a reasonable argument that the second form is easier to
edit etc, and that's all fine - but the performance argument is a
nonstarter.

Jon
Aug 11 '08 #7

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

Similar topics

8
by: rbt | last post by:
Would a Python process consume more memory on a PC with lots of memory? For example, say I have the same Python script running on two WinXP computers that both have Python 2.4.0. One computer has...
2
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
26
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
11
by: Paulo Eduardo | last post by:
Hi, All! We are developing one app for windows 95/98/Me/NT4.0/2000/XP/2003 using Visual C++ 6.0. We need to set the % of CPU Usage to app process. Is there an API to set % of CPU Usage? Can...
10
by: rdemyan via AccessMonster.com | last post by:
My app contains utility meter usage. One of the things we have to deal with is when a usage is clearly incorrect. Perhaps someone wrote the meter reading down incorrectly or made a factor of 10...
3
by: Sirisha | last post by:
I am using the following code to get the CPU usage PerformanceCounter myCounter; myCounter = new PerformanceCounter(); myCounter.CategoryName = "Processor"; myCounter.CounterName = "%...
1
by: spacecoyote | last post by:
I tried this: usage = "Something, by Spacecoyote\nusage: %prog file " parser = OptionParser(usage) test.py --help and I expected: Something, by Spacecoyote usage: test.py file
1
by: sowmya.rangineni | last post by:
Ours is a windows based application. When we open the application the CPU usage is 0% and the Memory Usage is 54,324Kb When I open a specific form in a module, the CPU usage is 0% and the...
2
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.