By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,979 Members | 960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,979 IT Pros & Developers. It's quick & easy.

Stupid question regarding use of Int or UInt

P: n/a
Let's assume you are developing a database application and you have an
ID field. You setup the ID field in the database as a 1 up increment
starting at zero.

Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive? Is there a performance penalty
using the uint type?

Furthermore, let's say I am building an application where I have
numbers that will only be positive. Should uint be user here? Again,
I almost always see int used, even if the business rules state the
number will never be negative.

Thanks

Endymion Keats
Jul 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Never really thought about it, but there is probably a slight overhead
involved with UInt. Int is a - dare I say - natural data type and
there is a lot of performance tweaking to make it work well. UInt
would probably need to be converted at some point.

I doubt there would be much difference either way, and you could use a
UInt with much higher numbers than an INT. Go for it.

Dan
On 16 Feb 2004 13:59:30 -0800, en*********@hotmail.com (Ender) wrote:
Let's assume you are developing a database application and you have an
ID field. You setup the ID field in the database as a 1 up increment
starting at zero.

Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive? Is there a performance penalty
using the uint type?

Furthermore, let's say I am building an application where I have
numbers that will only be positive. Should uint be user here? Again,
I almost always see int used, even if the business rules state the
number will never be negative.

Thanks

Endymion Keats


Jul 21 '05 #2

P: n/a
I'm not sure the exact reason, but I guess it could be a leftover of "old
habits" from VB6 days as it didn't support UInts (which would have been
ULongs in VB6 anyway).
Is there a performance penalty
using the uint type?
There shouldn't be. Both an Int and a UInt are 32bits. The only difference
is that one bit is used as a sign bit in the Int.
Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive?
It depends on the database field type. I guess if the database field is a
UInt, then technically, you should use a UInt as well. Depending on the
conversion routines used when loading the database field into your integer
variable, you might not get an error - simply a minus value if the value of
the field is greater than Int.MaxValue, but you could also get an overflow
exception.

My recommendation would be to defy convention and use UInt32 (or whatever
matches your database field).

Hope this helps,

Trev.


"Ender" <en*********@hotmail.com> wrote in message
news:47*************************@posting.google.co m... Let's assume you are developing a database application and you have an
ID field. You setup the ID field in the database as a 1 up increment
starting at zero.

Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive? Is there a performance penalty
using the uint type?

Furthermore, let's say I am building an application where I have
numbers that will only be positive. Should uint be user here? Again,
I almost always see int used, even if the business rules state the
number will never be negative.

Thanks

Endymion Keats

Jul 21 '05 #3

P: n/a
Hello Ender,

Maybe using the int datatype comes from the old days of VB, also VB.NET
(currently) did not support unsigned integer.
On the otherside the uint datatype is not CLS-Compliant datatype, while int
is. On the other hand you if you need only postive numbers, the uint
datatype will give you double the positive numbers when using int datatype.

Regards,


Maher
ma***@fr.fm

"Ender" <en*********@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Let's assume you are developing a database application and you have an
ID field. You setup the ID field in the database as a 1 up increment
starting at zero.

Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive? Is there a performance penalty
using the uint type?

Furthermore, let's say I am building an application where I have
numbers that will only be positive. Should uint be user here? Again,
I almost always see int used, even if the business rules state the
number will never be negative.

Thanks

Endymion Keats

Jul 21 '05 #4

P: n/a
These are some of the questions that you begin to run into when you
think about it a little.

The UINT is not CLS compliant, so you run into problems there,
especially if you want a VB.NET app to utilize your object (I belive
that VB.NET does not supports UINT, may be wrong on this).

However, if you let's pretened you have a SQL Integer field that goes
beyond the max int value. Then you need to use large ints.

It seems like a simple question, but there are so many different ways
to skin this and was wondering if anyone has seen anything from
Microsoft on the best approach.

I believe all of their examples I have seen use integer, which is
probably the way to go.

"Maher K. Al-Jendasi" <ma***@fr.fm> wrote in message news:<OA**************@TK2MSFTNGP11.phx.gbl>...
Hello Ender,

Maybe using the int datatype comes from the old days of VB, also VB.NET
(currently) did not support unsigned integer.
On the otherside the uint datatype is not CLS-Compliant datatype, while int
is. On the other hand you if you need only postive numbers, the uint
datatype will give you double the positive numbers when using int datatype.

Regards,


Maher
ma***@fr.fm

"Ender" <en*********@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Let's assume you are developing a database application and you have an
ID field. You setup the ID field in the database as a 1 up increment
starting at zero.

Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive? Is there a performance penalty
using the uint type?

Furthermore, let's say I am building an application where I have
numbers that will only be positive. Should uint be user here? Again,
I almost always see int used, even if the business rules state the
number will never be negative.

Thanks

Endymion Keats

Jul 21 '05 #5

P: n/a
> I belive
that VB.NET does not
supports UINT, may be wrong on this.
VB.net doesn't support the UInt32 directly, but you can still use it if you
want... e.g.
------------------------------
Dim nUint as System.UInt32

nUInt = Convert.ToUInt32(1500)
-------------------------------

Mathematical opreators and other stuff won't work too well though.

HTH,

Trev.

"Ender" <en*********@hotmail.com> wrote in message
news:47*************************@posting.google.co m... These are some of the questions that you begin to run into when you
think about it a little.

The UINT is not CLS compliant, so you run into problems there,
especially if you want a VB.NET app to utilize your object (I belive
that VB.NET does not supports UINT, may be wrong on this).

However, if you let's pretened you have a SQL Integer field that goes
beyond the max int value. Then you need to use large ints.

It seems like a simple question, but there are so many different ways
to skin this and was wondering if anyone has seen anything from
Microsoft on the best approach.

I believe all of their examples I have seen use integer, which is
probably the way to go.

"Maher K. Al-Jendasi" <ma***@fr.fm> wrote in message

news:<OA**************@TK2MSFTNGP11.phx.gbl>...
Hello Ender,

Maybe using the int datatype comes from the old days of VB, also VB.NET
(currently) did not support unsigned integer.
On the otherside the uint datatype is not CLS-Compliant datatype, while int is. On the other hand you if you need only postive numbers, the uint
datatype will give you double the positive numbers when using int datatype.
Regards,


Maher
ma***@fr.fm

"Ender" <en*********@hotmail.com> wrote in message
news:47*************************@posting.google.co m...
Let's assume you are developing a database application and you have an
ID field. You setup the ID field in the database as a 1 up increment
starting at zero.

Whenever I see programs, everyone always uses the int field to
represent the userID. Should this really be a uint since the field
will never be negative, only positive? Is there a performance penalty
using the uint type?

Furthermore, let's say I am building an application where I have
numbers that will only be positive. Should uint be user here? Again,
I almost always see int used, even if the business rules state the
number will never be negative.

Thanks

Endymion Keats

Jul 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.