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 3836
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*********@hot mail.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*********@ho tmail.com> wrote in message
news:47******** *************** **@posting.goog le.com... 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*********@ho tmail.com> wrote in message
news:47******** *************** **@posting.goog le.com... 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******* *******@TK2MSFT NGP11.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*********@ho tmail.com> wrote in message news:47******** *************** **@posting.goog le.com... 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.ToUInt3 2(1500)
-------------------------------
Mathematical opreators and other stuff won't work too well though.
HTH,
Trev.
"Ender" <en*********@ho tmail.com> wrote in message
news:47******** *************** **@posting.goog le.com... 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******* *******@TK2MSFT NGP11.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*********@ho tmail.com> wrote in message news:47******** *************** **@posting.goog le.com... 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 one instead of
another without any damage to the app.
regards obelix:)
|
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 this code:
DECLARE
@ContactID varchar(10),
|
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,
http://www.alistapart.com/articles/betterliving/
I read on...
|
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 as effective as possible. So I feel that using an int where
only an uint is needed is a waste.
e.g. something like (int i = 0; i < 100; i++)
|
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 C# project, but I cannot find a suitable marshal type
Is there a type that I can use to marshal a UINT*? If not, are there any other integrated...
|
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 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...
|
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 MyConst. I come from Delphi world and the
|
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(
StringBuilder pszBuffer, ref
uint pcchBuffer);
However, StringBuilder only accepts type int. Is it safe to cast uint to
int?
|
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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 we have to send another system
| |
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...
| |