Why do C# containers and GUI classes use int and not uint for size related members ?

Posted by smerlin on Stack Overflow See other posts from Stack Overflow or by smerlin
Published on 2010-04-24T17:47:28Z Indexed on 2010/04/24 17:53 UTC
Read the original article Hit count: 264

Filed under:
|

I usually program in C++, but for school i have to do a project in C#.

So i went ahead and coded like i was used to in C++, but was surprised when the compiler complained about code like the following:

        const uint size = 10;
        ArrayList myarray = new ArrayList(size); //Arg 1: cannot convert from 'uint' to 'int

Ok they expect int as argument type, but why ? I would feel much more comfortable with uint as argument type, because uint fits much better in this case.

Why do they use int as argument type pretty much everywhere in the .NET library even if though for many cases negative numbers dont make any sense (since no container nor gui element can have a negative size).

If the reason that they used int is, that they didnt expect that the average user cares about signedness, why didnt they add overloads for uint additonally ?

Is this just MS not caring about sign correctness or are there cases where negative values make some sense/ carry some information (error code ????) for container/gui widget/... sizes ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET