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 5 3826
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
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
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
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
> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: obelix |
last post by:
what kind of variable is UINT anyway, when I try to look it up in the
eMbVC++ HELP, i end up with nothing, nada, zero. So what is it and can
I cast it into simple int, and if not, can i simply use...
|
by: Martin Feuersteiner |
last post by:
Hi! I would be grateful for any advise regarding what I'm doing wrong.. My
brain is stuck. Probably some stupid simple mistake I don't see. Thanks very
much for your efforts!
Martin
I have...
|
by: rhat |
last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant.
Can anyone shed some light on what this will change and it will break stuff
as converting HTML to XHTML pages DO break things. see,...
|
by: Song Yun Zhao |
last post by:
Hi,
Just wondering what are the dis/advantages of using uint vs int. When
would be the best time to use it?
Personally I don't use uint that much, but I like to optimize my code
and make it...
|
by: ±èÀçȲ |
last post by:
//this code generates the error.
uint a=1,b=2;
Console.WriteLine(a << b);
Console.WriteLine(a >> b);
What problem does "uint type" have.?
| |
by: TT (Tom Tempelaere) |
last post by:
Hi people
I have a library built using MSVC6 which exports a method with the following signature
void library_method( UINT* sw_mode )
I am trying to use PInvoke to be able to call it from my...
|
by: Ender |
last post by:
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...
|
by: Jure Bogataj |
last post by:
Hello!
Why I cannot apply this operator to UINT or INT type in c# (VS 2005)?
uint MyConst;
uint SomeValue;
....
MyConst = MyConst & (!SomeValue)
Trying to erase certain bit inside...
|
by: Tim Sprout |
last post by:
The P/Invoke Interop Assistant (http://www.codeplex.com/clrinterop)
generates a signature for GetDefaultPrinter using an uint type for
pcchBuffer:
public static extern bool GetDefaultPrinter(
...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |