I have the following C# code-
switch (Convert.ToInt32(Encoding.ASCII.GetBytes(grdGrading.Text.Trim())))
grdGrading is a Data grid.
I am currently getting this error – Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.
Any ideas on what is causing that?
Convert.ToInt32()doesn’t work with arrays of bytes. It’s assuming that you’re passing it anobjectthat implementsIConvertible. UseBitConverter.ToInt32()instead.As noted by @AVD, however, it looks like what you really want to use is
Int32.TryParse().