Parse, ToString, and "Null"

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I was thinking that these two methods should be inverses of each other,
but that doesn't appear to be consistently the case in MS code. Also,
I kind of think that Parse should not be case sensitive; 1e10 == 1E10.
For example:

try
{
on = OracleNumber.Parse("Null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // System.FormatException
}

try
{
s16 = SqlInt16.Parse("Null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // No exception; s16 =
SqlInt16.Null
}


try
{
s32 = SqlInt32.Parse("Null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // No exception; s32 =
SqlInt16.Null
}

try
{
s16 = SqlInt16.Parse("null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // {"Input string was not
in a correct format."}
}

try
{
s32 = SqlInt32.Parse("null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // No exception; s32 =
SqlInt16.Null
}


try
{
sdt = SqlDateTime.Parse("Null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // no exception
}

try
{
sdt = SqlDateTime.Parse("null");
}
catch (Exception e)
{
Console.WriteLine(e.ToString()); // {"String was not
recognized as a valid DateTime."}
}

// Why DateTime in the message? The type I'm parsing is an
SqlDateTime.

Anyone know if case-sensitivity is expected to change?
Same question for consistency between the OracleClient types (written
by MS) and the SqlClient types?

Anyone happen to know how the .Net provider written by Oracle behaves?

-Chris
 
Well, I appreciate the links, but I take x.Parse(string) to mean, "Take
this string and attempt to create an object of type x that would mean
the same as the content of the string." This has nada to do with case
sensitivity of identifiers, which is the subject of the first link; a
variable foo is categorically different from a string "foo"; null as a
language element is categorically different from a string whose value
is "null".

So, thanks, but does anyone else have a take on this?

-Chris
 
Back
Top