Java Long to c#

theartha
theartha used Ask the Experts™
on
Hi There,

I am new to c# but experience in Java.

When I declare a variable recNumber

private Long recNumber;

this.recNumber = new Long(0);

I got the below error.

The type or namespace name 'Long' could not be found (are you missing a using directive or an assembly reference?)

Please advice.

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Try...

           
 long recNumber;
 recNumber = 0;
Top Expert 2011
Commented:
There is no Long in C# or the .NET Framework.  The C# built-in type is long, which is mapped to the .NET Framework System.Int64 type.

Unlike Java, C#'s long can also be used as a reference type.  So, the following is valid in C#:

long mylong = 123;

Console.WriteLine(mylong.ToString());
Console.WriteLine(mylong.GetHashCode());
Console.WriteLine(long.Parse("456"));
Console.WriteLine(678.GetType());
Console.WriteLine(678L.GetType());

/* Output
123
123
456
typeof (Int32) 
typeof (Int64) 
*/

Open in new window


long (C#)
http://msdn.microsoft.com/en-us/library/ctetwysk%28v=VS.80%29.aspx

I hope this helps.
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
@wdosanjos
Unlike Java, C#'s long can also be used as a reference type.
That statement is a bit misleading. long, and other value types, is boxed into a reference type. I only point out the difference because there can be times when knowing this is important  = )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial