@SomeFunction() ???????

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Yello,
Quick Q:
I used a converter to convert vb code to C# (and not very well I might add.)
One of the things it did is an @ symbol to a few of the functions. I know
what it means when you do it to a string, but what about a function?

eg:
_numberOfRecords = @BitConverter.ToInt32(foxArray, 4);

No errors are thrown but I dont understand it.

Thanks in advance for all help on this issue.
 
TheMadHatter said:
Yello,
Quick Q:
I used a converter to convert vb code to C# (and not very well I might
add.)
One of the things it did is an @ symbol to a few of the functions. I know
what it means when you do it to a string, but what about a function?

eg:
_numberOfRecords = @BitConverter.ToInt32(foxArray, 4);

No errors are thrown but I dont understand it.

Thanks in advance for all help on this issue.

The @ symbol is used to reference variables that have the same name as a C#
keyword. For example, the following code was pulled from the MSDN library:

class @class
{
public static void @static(bool @bool) {
if (@bool)
System.Console.WriteLine("true");
else
System.Console.WriteLine("false");
}
}
class Class1
{
static void M() {
class.static(true);
}
}


HTH! :)

Mythran
 
Hi,
you can use the @ symbol to use reserved keywords as variable names /
methods etc. So you could have a variable called string or other things like
that. i.e.

using System;

namespace ConsoleApplication22
{
class Program
{
static void Main(string[] args)
{
string @string = "hello";
Console.WriteLine(@string);
@int();
Console.ReadLine();
}

public static void @int()
{
Console.WriteLine("hello again");
}
}
}
 
In addition to what others have said it's most obvious purpose to use
an assembly developed in another language in which the developer
unwittingly used C# keywords in the public interface. I have not yet
had a need to use it in this manner though.

Brian
 
Mark R. Dawson said:
you can use the @ symbol to use reserved keywords as variable names /
methods etc. So you could have a variable called string or other things like
that. i.e.

<snip>

It should be noted, by the way, that this should be avoided wherever
possible. It's really available so that you can use code written in
other languages with different keywords, which may have used a C#
keyword as an identifier. It would be madness to write your own C# code
which deliberately used keywords as identifiers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top