I haven't done much with C#, but this just seems odd to me, so I figured I'd ask to see what is going on.
I have a datareader that gets one field from a database. That field is usually a string, but in one case, I'm looking for an integer field.
I had this line:
that worked fine, as there is a form of the constructor that takes two strings as arguments. However, I then realized that I needed to do something slightly different in one highly specialized case, so I wrote this line:Code:New SelectedListItem(dr[0].ToString(),dr[0].ToString())
This gives a warning because dr[0] could be null. It can't actually, because that line is inside the else case where I do something different if dr[0] is null, but that's unimportant.Code:string st1 = dr[0].ToString();
My first question is why is it fine to use the code as an argument to a constructor that takes a string (but not a nullable string, as far as I can see), but it isn't okay to assign it to a string variable? Is the constructor assuming that it's arguments might just be nullable? Why wouldn't the argument be string? in that case?
Anyways, I then tried to do this:
but that doesn't work because dr[0] is not always a string. In that one case, it is an integer, so GetString() throws an exception.Code:string st1 =dr.GetString(0);
So, my second question is: There must be some easy way to solve this, though I'm not seeing it, and I'm not quite sure how to put it in the form of a searchable question. So, what am I missing?

