I am new to C#, I have some background in C++ and C and this is why I fail to grasp, why Lists<> are indexed by int
and not some unsigned integer like uint
. This is highly illogical, because there cannot be an element i.e. -1 or so.
This came up when the following code failed to run:
List<string> some_list = new List<string>();
/* Insert some strings */
for (uint i = 0; i < some_list.Count; ++i) {
string element = some_lists[i]; // Error: No possible conversion from uint to int
/* do something with string_element */
}
In C++ this would give me a compiler warning, but still compile fine. So what is C#'s reasoning for using signed integers as indices in, say, Lists? This does not look very sharp to me, but maybe someone can enlighten me.