Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does .NET use int instead of uint in certain classes?

Tags:

c#

.net

I always come across code that uses int for things like .Count, etc, even in the framework classes, instead of uint.

What's the reason for this?

like image 536
Joan Venge Avatar asked Apr 23 '09 16:04

Joan Venge


People also ask

Should I use UINT or int?

Since we use number with positive and negative integers more often than positive integers only, the type Int is the signed integers. If we want a value without a sign, then we use the type UInt . UInt creates a integer of the same bit size as the device's processor can handle.

What is the difference between int and UINT in C#?

uint means “unsigned integer” while int means “signed integer”. Unsigned integers only contain positive numbers (or zero).

Should I use unsigned int or uint32_t?

The Google C++ style guide recommends avoiding unsigned integers except in situations that definitely require it (for example: file formats often store sizes in uint32_t or uint64_t -- no point in wasting a signedness bit that will never be used).

What is Uint data type in C#?

C# Language Keywords uint An unsigned integer, or uint, is a numeric datatype that only can hold positive integers. Like it's name suggests, it represents an unsigned 32-bit integer. The uint keyword itself is an alias for the Common Type System type System.


2 Answers

UInt32 is not CLS compliant so it might not be available in all languages that target the Common Language Specification. Int32 is CLS compliant and therefore is guaranteed to exist in all languages.

like image 149
dtb Avatar answered Sep 20 '22 14:09

dtb


int, in c, is specifically defined to be the default integer type of the processor, and is therefore held to be the fastest for general numeric operations.

like image 30
Adam Davis Avatar answered Sep 21 '22 14:09

Adam Davis