Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krishnaneeraja
    New Member
    • Mar 2008
    • 21

    Unable to cast object of type 'System.Byte[]' to type 'System.IConvertible'.

    Hi,

    I wrote code(C#.net) in this way to find ASCII value of an URL.but i got some errors.plz rectify anyone.

    public int[] stringorder(str ing str)
    {
    int[] result=new int[20];
    char[] str1=new char[1];

    for (int i = 0; i < str.Length; i++)
    {
    str1[0]=str[i];
    result[i] = System.Convert. ToInt32(System. Text.ASCIIEncod ing.Default.Get Bytes(str1));

    }
    return result;

    }
    error:Unable to cast object of type 'System.Byte[]' to type 'System.IConver tible' at result[i].



    thanks.
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Originally posted by krishnaneeraja
    Hi,

    I wrote code(C#.net) in this way to find ASCII value of an URL.but i got some errors.plz rectify anyone.

    public int[] stringorder(str ing str)
    {
    int[] result=new int[20];
    char[] str1=new char[1];

    for (int i = 0; i < str.Length; i++)
    {
    str1[0]=str[i];
    result[i] = System.Convert. ToInt32(System. Text.ASCIIEncod ing.Default.Get Bytes(str1));

    }
    return result;

    }
    error:Unable to cast object of type 'System.Byte[]' to type 'System.IConver tible' at result[i].



    thanks.
    I'm not sure exactly what you're trying to achieve with this code but if you're after the byte representation of your URL, you'd need to do something like:

    Code:
    public byte[] stringOrder(string str){
      Encoding oEnc = Encoding.ASCII;
      byte[] result = oEnc.GetBytes(str);
    }

    Comment

    Working...