473,383 Members | 1,868 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,383 software developers and data experts.

using of "@" before classname

i was looking in some code in which i found that it is using @ keyword before
class name and constructor like this

public class @MyClass
{
public @MyClass
{
}
}

can anyone please help me to know that when and why we use this keyword
before classname.

Thanks
Abhi
Jun 27 '08 #1
9 2694
Abhi wrote:
i was looking in some code in which i found that it is using @ keyword before
class name and constructor like this

public class @MyClass
{
public @MyClass
{
}
}

can anyone please help me to know that when and why we use this keyword
before classname.

Thanks
Abhi
If, for some reason, you need/want to use a reserved word as an
identifier, you need to prefix it with @

Try:

Int32 @this = 0;
Int32 this = 0;

and you'll notice that the compiler will complain about the second
declaration since "this" is a reserved word.

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jun 27 '08 #2
On May 28, 6:47*am, Abhi <A...@discussions.microsoft.comwrote:
i was looking in some code in which i found that it is using @ keyword before
class name and constructor like this

public class @MyClass
{
* * public @MyClass
* *{
* *}

}

can anyone please help me to know that when and why we use this keyword
before classname.

Thanks
Abhi
Hi,

FRankly I have never seen this before, where did you see it ?
Jun 27 '08 #3
On May 28, 5:47*am, Abhi <A...@discussions.microsoft.comwrote:
i was looking in some code in which i found that it is using @ keyword before
class name and constructor like this

public class @MyClass
{
* * public @MyClass
* *{
* *}

}

can anyone please help me to know that when and why we use this keyword
before classname.

Thanks
Abhi
It allows reserved words to be used as identifiers. It's use in C# is
not that common. The reasoning behind that is that all keywords in C#
begin with a lowercase character and if you follow the .NET naming
guidelines you would make all public API identifiers begin with a
capital letter. So even if your API was developed in another language
it's still not going to be likely that you encounter an identifier-
keyword collision in C#.

It's a lot more likely that you would need to use VB.NET's equivalent
[] characters to surround identifiers since VB is not case sensitive.
For example, I could declare a class called Stop in C# not knowing
that it was a keyword in VB.NET forcing developers of VB.NET to use
[]'s if they wanted to use my class.

Jun 27 '08 #4
Lasse Vågsæther Karlsen wrote:
Abhi wrote:
>i was looking in some code in which i found that it is using @ keyword
before class name and constructor like this
If, for some reason, you need/want to use a reserved word as an
identifier, you need to prefix it with @
But it would be a much better idea to choose another name.

Arne
Jun 27 '08 #5
On May 28, 9:11*pm, Arne Vajhøj <a...@vajhoej.dkwrote:
But it would be a much better idea to choose another name.

Arne
You might not have that option. See my other post on this thread.

Jun 27 '08 #6
Brian Gideon wrote:
On May 28, 9:11 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>But it would be a much better idea to choose another name.

You might not have that option. See my other post on this thread.
If the API is given by someone else (possible not coding in C#), then
another name may not be an option.

But given the reserved words in C# are what I would call "relative
common" reserved words, then I would say the chance is low, but there
are a few candidates: lock, event, fixed, yield, checked !

Arne

Jun 27 '08 #7
You can see the IDE creating this for you by simply adding a new class using
IDE.

For example, right click on the project, select Add Class... when prompted
to enter a name for the class choose a name such as "this" or "int". Click
ok and you will see the designer adding the @ character at the beginning of
the class name (the file name will not be affected).
"Ignacio Machin ( .NET/ C# MVP )" <ig************@gmail.comwrote in
message
news:b1**********************************@h1g2000p rh.googlegroups.com...
On May 28, 6:47 am, Abhi <A...@discussions.microsoft.comwrote:
i was looking in some code in which i found that it is using @ keyword
before
class name and constructor like this

public class @MyClass
{
public @MyClass
{
}

}

can anyone please help me to know that when and why we use this keyword
before classname.

Thanks
Abhi
Hi,

FRankly I have never seen this before, where did you see it ?

Jun 27 '08 #8
On May 28, 9:57*pm, Arne Vajhøj <a...@vajhoej.dkwrote:
But given the reserved words in C# are what I would call "relative
common" reserved words, then I would say the chance is low, but there
are a few candidates: lock, event, fixed, yield, checked !
Even in those cases it's still not likely as long as the API developer
followed the naming guideline of capitalizing the first character of
an identifier. I have been doing some VB.NET lately and used a
library written in C# that really did have an Event class. Well,
Event is a keyword in VB.NET so I have to surround it with
[]'s...annoying.
Jun 27 '08 #9
Brian Gideon wrote:
On May 28, 9:57 pm, Arne Vajhøj <a...@vajhoej.dkwrote:
>But given the reserved words in C# are what I would call "relative
common" reserved words, then I would say the chance is low, but there
are a few candidates: lock, event, fixed, yield, checked !

Even in those cases it's still not likely as long as the API developer
followed the naming guideline of capitalizing the first character of
an identifier.
Not likely.

But not as unlikely as it may appear - because "not knowing C# keywords"
and "not knowing naming guideline" is undoubtedly correlated.

Arne
Jun 27 '08 #10

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

Similar topics

0
by: Justin | last post by:
Hi. I decided to tidy up some of my queries, but I came across something that stumpt me: mysql> SELECT -> jobs.jobId, -> jobs.active, -> jobs.title, -> jobs.listed, -> ...
0
by: Simon | last post by:
Hi, I'm trying to serialize an XML document to a file using XERCES-C++ 2.1.0 . The Document contains an internal DTD. The DTD contains some elements with default values like the following...
0
by: antsays | last post by:
I am trying to serialize a collection to disk using the code provided. This works just fine but when I try do copy and past the xml file to another location or sometimes even just click on the...
7
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the...
5
by: charliewest | last post by:
I've implemented the USING statement to ensure that my newly created sql connection closes when my method is finished using it. The USING statement is wrapped in try/catch error handling statement....
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
21
by: comp.lang.tcl | last post by:
set php {<? print_r("Hello World"); ?>} puts $php; # PRINTS OUT <? print_r("Hello World"); ?> puts When I try this within TCL I get the following error:
0
Fary4u
by: Fary4u | last post by:
Hi Guys i'm trying to upload a file, i've tried 3 different methods but still not work out i don't know how to over come this problem hidden file value, multiple form or popup uploading. 1-...
3
by: sejal17 | last post by:
hello Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.