472,979 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,979 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 1126
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.