473,687 Members | 3,230 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 #1
14 7417
Int is a primative type.
However, the runtime can "box" a primative so it can operate as an Object,
thereby keeping the paradigm that everything can be treated as having the
object base type.
Note that value types can indeed have methods, and static methods (like
Parse) don't require an instance handle, so boxing isn't required in that
particular case. Look up "value type" and "boxing" in the MSDN to get more
info.
So, in short, int (which is really just int32 in C#) isn't an object, but it
can be treated as an object.

-Rob Teixeira [MVP]

"Matt" <ma*******@hotm ail.com> wrote in message
news:eu******** ******@TK2MSFTN GP10.phx.gbl...
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 #2
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:
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. method(); //doesn't make sense ??

Please advise. Thanks!


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.

In C# (in IL generally) there is no such thing as a 'primitive type'.
Everything is a class or an object. There are two types of classes -
Value types and Reference types. Value types are like primitive types
- more so than reference types anyway - but the importasnt thing to
remember is that there are NO 'primitive' types in the sense that that
is usually used.

int (that is, System.Int32) is not an object. It is a class. As a
class it can - and in fact does - have static methods which is what
..Parse(..) is.

Once again, forget primitive types! They don't exist!

--
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 #3
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.

--
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 #4

"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:
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. method(); //doesn't make sense ??

Please advise. Thanks!


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.


I don't think this is true. In C# int is the same as System.Int32. It
doesn't matter what you're running on. There are BCL types that correspond
to natural word size of the machine but they aren't called int.
In C# (in IL generally) there is no such thing as a 'primitive type'. Everything is a class or an object. There are two types of classes -
Value types and Reference types. Value types are like primitive types
- more so than reference types anyway - but the importasnt thing to
remember is that there are NO 'primitive' types in the sense that that
is usually used.

int (that is, System.Int32) is not an object. It is a class. As a
class it can - and in fact does - have static methods which is what
.Parse(..) is.

Once again, forget primitive types! They don't exist!


I would argue that they do and they don't. There are mappings to CIL but
when your programming in C# you are programming in C# and not in CIL. From
that point of view I would say that C# does have "primitive types" or more
accurately (as defined by the ECMA standard) it has simple types (11.1.3).
It all depends on your perspective.
HTH
Cheers
Jon Jagger


Nov 15 '05 #5

"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:eo******** *****@tk2msftng p13.phx.gbl...
Int is a primative type.


No.

There is no such thing as a "primitive type" in the CLS:

Int is a STRUCT. System.Int32.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
Nov 15 '05 #6

"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:
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. method(); //doesn't make sense ??

Please advise. Thanks!


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.


Wrong. C# int is System.Int32 - always. Read the language specifications,
please.
In C# (in IL generally) there is no such thing as a 'primitive type'.
Right.
Everything is a class or an object. There are two types of classes -
Wrong.

Besides classes, there are STRUCTS. Actually, everything is an INSTANCE of a
TYPE - either based on a CLASS or based on a STRUCT, or actually on an ENUM.

The word "object" is mostly reserved for instances of classes, but often
used for instances of structs, too. But technocally, everything is NOT a
class or an object - everything is a TYPE or an instance of a type.
Value types and Reference types. Value types are like primitive types
- more so than reference types anyway - but the importasnt thing to
remember is that there are NO 'primitive' types in the sense that that
is usually used.
Right so far. Though this is contradicting what you said further up.
int (that is, System.Int32) is not an object. It is a class. As a
No, it is NOT a class. System.Int32 is a TYPE, actually a type of a STRUCT.
STRUCTS are NOT classes.

The use of the word "Class" is totally wrong here.
class it can - and in fact does - have static methods which is what
.Parse(..) is.
No, not as a class. As a TYPE. TYPE is the word you should use here.
Once again, forget primitive types! They don't exist!


Right.

Just please get your use of words clear. You use "Class" and "object" in
different contradicting meanings all over your post - and seldon im the
technically correct one.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)
Nov 15 '05 #7
Ok, "value type" if you want to get picky :-)

Whether or not there are "primitive" types in the CLI (or more specifically
in C#) is a little debatable. For starters, an instance of Int32 produces a
single 32-bit value in memory. Additionally, in C# specs (4.1.3), all the
integral types, decimal types, and bool are defined as a special case of
Value Type referred to as "simple type". They have do in fact behave
slightly differently from normal STRUCTs. Specifically:
* instances can be created in code by use of literals
* when all operands of an expression are literal constants of Simple Type,
the compiler can evaluate the expression at compile time. "Expression s
defined by other struct types are not considered constant expressions."
* By using "const", you can declare constants of Simple Types. "It is not
possible to have constants of other struct types"
* "Conversion s involving simple types can participate in evaluation of
conversion operators defined by other struct types, but a user-defined
conversion operator can never participate in evaluation of another
user-defined operator"

-Rob Teixeira [MVP]

"Thomas Tomiczek [MVP]" <t.********@tho na-consulting.com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .

"Rob Teixeira [MVP]" <RobTeixeira@@m sn.com> wrote in message
news:eo******** *****@tk2msftng p13.phx.gbl...
Int is a primative type.


No.

There is no such thing as a "primitive type" in the CLS:

Int is a STRUCT. System.Int32.

Thomas Tomiczek
THONA Software & Consulting Ltd.
(Microsoft MVP C#/.NET)

Nov 15 '05 #8
On Sun, 4 Jan 2004 18:37:29 +0100 in article
<ua************ **@TK2MSFTNGP12 .phx.gbl> in
microsoft.publi c.dotnet.langua ges.csharp , "Thomas Tomiczek [MVP]"
<t.********@tho na-consulting.com> wrote:

Wow! Can of worms time! OK -

"Simon Smith" <si************ ****@snowvalley .com> wrote in message
news:vn******* *************** **********@4ax. com...
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:
>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 thecase, >can we say "int" is an object??
>
>Because methods should operate on object, not on primitive type.
>
>object1.method (...); //make sense
>primitiveType. method(); //doesn't make sense ??
>
>Please advise. Thanks!
>
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.


Wrong. C# int is System.Int32 - always. Read the language specifications,
please.


Apologies and thanks to all who corrected me. I thought what I said
was true, but obviously not. Thanks to all for teaching me!
In C# (in IL generally) there is no such thing as a 'primitive type'.
Right.
Everything is a class or an object. There are two types of classes -


Wrong.

Besides classes, there are STRUCTS. Actually, everything is an INSTANCE of a
TYPE - either based on a CLASS or based on a STRUCT, or actually on an ENUM.


I think the next clause of my sentence shows that I know that there
are value and reference types. The word I should have used instead of
Class was Type.
The word "object" is mostly reserved for instances of classes, but often
used for instances of structs, too. But technocally, everything is NOT a
class or an object - everything is a TYPE or an instance of a type.
I know an object is an instance of a type.
Value types and Reference types. Value types are like primitive types
- more so than reference types anyway - but the importasnt thing to
remember is that there are NO 'primitive' types in the sense that that
is usually used.
Right so far. Though this is contradicting what you said further up.


Probably I'm being stupid, but I don't see how I contradicting myself.
int (that is, System.Int32) is not an object. It is a class. As a
No, it is NOT a class. System.Int32 is a TYPE, actually a type of a STRUCT.
STRUCTS are NOT classes.

The use of the word "Class" is totally wrong here.


OK, I'll take that. I didn't want to get into ADT's etc, I wanted to
emphasise that there was no such think as a primitive, just two types
of what I called a class for emphasis.
class it can - and in fact does - have static methods which is what
.Parse(..) is.


No, not as a class. As a TYPE. TYPE is the word you should use here.


OK already!
Once again, forget primitive types! They don't exist!


Right.

Just please get your use of words clear. You use "Class" and "object" in
different contradicting meanings all over your post - and seldon im the
technically correct one.

I don't think I do that. I only used the word 'object' once I think
Causing confusion about class and type I will accept, but not about
type (or class) and object. But whatever.

I learnt from your and Jon Skeet's and Jon Jagger's posts, so thanks!
--
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 #9
On Sun, 4 Jan 2004 16:57:52 -0000 in article
<ur************ **@TK2MSFTNGP12 .phx.gbl> in
microsoft.publi c.dotnet.langua ges.csharp , "Jon Jagger"
<jo*@jaggersoft .com> wrote:

"Simon Smith" <si************ ****@snowvalley .com> wrote in message

int (that is, System.Int32) is not an object. It is a class. As a
class it can - and in fact does - have static methods which is what
.Parse(..) is.

Once again, forget primitive types! They don't exist!


I would argue that they do and they don't. There are mappings to CIL but
when your programming in C# you are programming in C# and not in CIL. From
that point of view I would say that C# does have "primitive types" or more
accurately (as defined by the ECMA standard) it has simple types (11.1.3).
It all depends on your perspective.
HTH
Cheers
Jon Jagger


That's something I didn't know - I had assumed that they were standard
value types (albeit sealed). Thanks!
--
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 #10

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

Similar topics

134
9029
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
3
2265
by: Juha Nieminen | last post by:
Consider this code: void foo(int& i) { i += 10; } int main() { int a = 1;
1
6599
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
10995
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
8590
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
8528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8786
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
7621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6453
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5807
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
4321
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
4547
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.