as string caused me a problem when dealing with object arrays. The values after execution are shown in the comments. Should it work this way?
object[] array = new object[2];
array[0] = 0.33;
array[1] = "0.33";
string a = array[0] as string; // a == null !!!??????
string b = array[1] as string; // b == "0.33"
string a2 = array[0] == null ? "" : array[0].ToString(); // a2 == "0.33"
string a3 = Convert.ToString(array[0]); // a3 == "0.33"
Yes, it should.
asis a cast operator.It can only be used to cast an object to a type that it actually is (or a superclass thereof).
x as Yreturnsnullifxisn’t aY.