Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does .NET Framework not use unsigned data types? [duplicate]

Possible Duplicate:
Why is Array.Length an int, and not an uint

Is there is a reason behind it .NET Framework not using unsigned data types?

Shouldn't I be adopting them in my code, but for example, the Count property of a List<> is an int. You can't have a negative count, so why shouldn't it be defined as a uint? Should I use only int's even though I know the count can not be negative?

like image 671
esac Avatar asked Oct 14 '10 16:10

esac


People also ask

Does c# support unsigned numbers?

NET aware languages do allow unsigned ints. E.g. in C# you can use uint. However, as they not CLS compliant if you expose them outside of your assembly then you might find that other developers using a different language will have problems using your classes.

Why is Uint not CLS compliant?

In any case, the reason unsigned integers are not CLS compliant is that Microsoft decided that languages didn't have to support unsigned integers in order to be considered "CLS compatible".

What is ULong?

Ulong is an unsigned long integer datatype in computer programming languages and operating systems. Ulong tea, an alternate spelling for oolong tea.

What is unsigned in C#?

uint is a keyword that is used to declare a variable which can store an integral type of value (unsigned integer) from the range of 0 to 4,294,967,295.


1 Answers

Unsigned numeric types are not CLS compliant so they should not be used for any API - especially the .NET framework.

Basically, CLS compliant code only utilizes types that are available in all .NET languages. Some languages (like VB.NET) does not support unsigned numeric types.

like image 146
Andrew Hare Avatar answered Sep 27 '22 21:09

Andrew Hare