Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Tuesday, January 12, 2016

Is there a Integer class in c#?

Is there a Integer class in c#?


We have Integer class in JAVA, but I couldn't find any equivalent class in C#? Does c# have any equivalent? If not, how do I get JAVA Integer class behavior in c#?

Why do I need this?

It is because I'm trying to migrate JAVA code to c# code. If there is an equivalent way, then code migration would be easier. To addon, I need to store references of the Integer and I don't think I can create reference of int or Int32.

Answer by Soumitri Pattnaik for Is there a Integer class in c#?


No Integer class but you have a similar Int32 structure.

Answer by recursive for Is there a Integer class in c#?


C# has a unified type system, so int can be implicitly boxed into an object reference. The only reason Integer exists in Java is so that it can be converted to an object reference and stored in references to be used in other container classes.

Since C# can do that without another type, there's no corresponding class to Integer.

Answer by PC Luddite for Is there a Integer class in c#?


The beauty of C# is that it has a unified type system. Everything derives from object, even primitive types. Because of this, all keywords are simply aliases for a corresponding class or struct. Java does not use a unified type system, so a separate Integer class is required to wrap the int primitive. In C# int is synonym for the Int32 struct.

What you're looking for has been right in front of you the whole time. Start using the dot notation directly on the int keyword (i.e. int.whatever()) to access the all goodness of the .NET version of the Javian Integer class.

Answer by HimBromBeere for Is there a Integer class in c#?


Code migration wont work out of the box for any type of language without any manual changes. There are things such as a class Integer that simply does not exist within (C# why should it anyway, see recursives answer), so youd have to do some work on your own. The nearest equivalent to what youre after is Int32 or its alias int. However you may of course write your own wrapper-class:

public class Integer {      public int Value { get; set; }  }  

And add a custom cast to int:

public static implicit operator Int32(Integer x) { return this.Value; }    

Answer by mimi87 for Is there a Integer class in c#?


c# have a integer type called int link is here

https://msdn.microsoft.com/en-us/library/5kzh1b5w.aspx

Answer by Xenia Rick for Is there a Integer class in c#?


The reason Java users use Integer (or any other class version of a base type) is to create variables that can be set to null. C# may have a unified type system but you cannot do int var = nullin C# (you cannot do it in Java either). I've done some data processing for the medical industry and it's critical to know if a doctor/patient has answered a question or not. Using null to indicate no answer provided is a clean way to do it. The original PO will need to create his own Integer class.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.