473,839 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is "int" a primitive type or an object??

I want to know if "int" is a primitive type, or an object?

For example, the following two approaches yield the same result.
int t1 = int.Parse(TextB ox2.Text); //method 1
int t2 = System.Int32.Pa rse(TextBox2.Te xt); //method 2


And people said "int" is a C# alias for "System.Int 32". If this is the case,
can we say "int" is an object??

Because methods should operate on object, not on primitive type.

object1.method( ...); //make sense
primitiveType.m ethod(); //doesn't make sense ??

Please advise. Thanks!
Nov 15 '05
14 7467
On Sun, 4 Jan 2004 16:41:19 -0000 in article
<MP************ ************@ms news.microsoft. com> in
microsoft.publi c.dotnet.langua ges.csharp , Jon Skeet [C# MVP]
<sk***@pobox.co m> wrote:
Simon Smith <si************ ****@snowvalley .com> wrote:
The C# compiler translates all references to 'int' to 'System.Int32'.
Thus any use of 'int' is exactly the same as using System.Int32 - no
difference whatsoever. Why use int, then, apart from a bit less
typing? On 64-bit systems it will translate to 'System.Int64' - i.e.
use the appropriate size for the machine it's running on.


No it won't. In C#, int is *always* defined as a shorthand for Int32,
thank goodness.

Thanks for putting me right.

I had thought that the purpose of it was to help the transition
between 32 and 64 bit machines, mapping to an integer of the native
word size. (I have vague memories of going from VB 3 to VB4+ where
integer stayed 16 bits and needed to be changed to long IIRC for
performance. But I didn't think it through.....)
Thinking about it, that doesn't make sense because then what's the
purpose of decimal and string etc? Not that they need the same
purpose, but anyway.
I guess it must be a readability thing....

Cheers!
--
Simon
simon dot smith at snowvalley dot com
"Insomnia is a small price to pay for the stuff you read on UseNet"
Nov 15 '05 #11

"Simon Smith" <si************ ****@snowvalley .com> wrote in message
news:vn******** *************** *********@4ax.c om...
On Sat, 3 Jan 2004 18:38:22 -0800 in article
<eu************ **@TK2MSFTNGP10 .phx.gbl> in
microsoft.publi c.dotnet.langua ges.csharp , "Matt"
<ma*******@hotm ail.com> wrote:

Once again, forget primitive types! They don't exist!
While they may be named simple types by higher level languages like C#, they
do exist at the CLR level.
Primitive types as defined in mscorlib have a special encoding in their
signatures, this is done for performance reasons.
There is even a CLR implemtated function called CorIsPrimitiveT ype thtat
returns true if a type is primitive.

Willy.

--
Simon
simon dot smith at snowvalley dot com
"Insomnia is a small price to pay for the stuff you read on UseNet"

Nov 15 '05 #12

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:eF******** ******@TK2MSFTN GP11.phx.gbl...

"Simon Smith" <si************ ****@snowvalley .com> wrote in message
news:vn******** *************** *********@4ax.c om...
On Sat, 3 Jan 2004 18:38:22 -0800 in article
<eu************ **@TK2MSFTNGP10 .phx.gbl> in
microsoft.publi c.dotnet.langua ges.csharp , "Matt"
<ma*******@hotm ail.com> wrote:

Once again, forget primitive types! They don't exist!
While they may be named simple types by higher level languages like C#,

they do exist at the CLR level.
Primitive types as defined in mscorlib have a special encoding in their
signatures, this is done for performance reasons.
There is even a CLR implemtated function called CorIsPrimitiveT ype thtat
returns true if a type is primitive.
I think you are completely true: although "int" is just a sort of "shortcut"
for "System.Int 32" in C#, there are special instruction in CIL to deal with
what we usually call "primitive types" (John Gough calls them "build-in
types" in his book "Compiling for the .NET CLR"). As a consequence, these
types are special; if not, the compiler should generate a method call to add
two numbers, something like Int32.Add(Int32 a, Int32 b).

Have a nice day
GV


Willy.

--
Simon
simon dot smith at snowvalley dot com
"Insomnia is a small price to pay for the stuff you read on UseNet"


Nov 15 '05 #13
Willy Denoyette [MVP] <wi************ *@pandora.be> wrote:
There is even a CLR implemtated function called CorIsPrimitiveT ype thtat
returns true if a type is primitive.


Similarly there's Type.IsPrimitiv e:

<quote>
Property Value
true if the Type is one of the primitive types; otherwise, false.

Remarks
The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32,
UInt32, Int64, UInt64, Char, Double, and Single.
</quote>

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #14
Jon,

Absolutely right, and Type.IsPrimitiv e calls the internal function
CorIsPrimitiveT ype.

Thanks,

Willy.

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** @msnews.microso ft.com...
Willy Denoyette [MVP] <wi************ *@pandora.be> wrote:
There is even a CLR implemtated function called CorIsPrimitiveT ype thtat
returns true if a type is primitive.


Similarly there's Type.IsPrimitiv e:

<quote>
Property Value
true if the Type is one of the primitive types; otherwise, false.

Remarks
The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32,
UInt32, Int64, UInt64, Char, Double, and Single.
</quote>

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #15

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

Similar topics

134
9120
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
3
2275
by: Juha Nieminen | last post by:
Consider this code: void foo(int& i) { i += 10; } int main() { int a = 1;
1
6611
by: Claire | last post by:
"Comparison to integral constant is useless; the constant is outside the range of type 'int'" How can I fix this compiler warning, please, for the following pseudocode? int m_nError; m_nError = somedriverapi.DoSomething(); if (m_nError != 0x8010002F) foobar; << compiler warning here thankyou Claire
2
11013
by: mmiikkee13 | last post by:
>>a_list = range(37) .... print k, v .... Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'int' object is not iterable What 'int' object is this referring to? I'm iterating over a dict, not an int.
0
9855
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10649
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10295
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7018
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.