Data type conversion-Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Badri Mohan

    #1

    Data type conversion-Help

    Hi Guys

    I am tired of finding solution to this..
    Help me when u find time

    How to convert from


    int[] to byte[] //right now i do by a for loop
    byte[] to int[] //right now i do by a for loop
    int[] to string //I donno how to do this
    string to int[] //I donno how to do this

    Regards
    Badri


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Data type conversion-Help

    Badri,

    You can use the static Copy method on the Array class to do this.
    However, it will not work in all cases. It will work for your second case
    only. The reason it won't work for the others is as follows:

    1 - You have the potential to lose information on the conversion of each
    integer element to a byte element.
    3 - The Copy method doesn't know how to convert between an int and a string.
    You have to loop through each element and do the conversion yourself.
    4 - The same as #3, but vice versa.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Badri Mohan" <bmohan@NOSPAMu ncc.edu> wrote in message
    news:OG8NV5PuDH A.3496@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hi Guys
    >
    > I am tired of finding solution to this..
    > Help me when u find time
    >
    > How to convert from
    >
    >
    > int[] to byte[] //right now i do by a for loop
    > byte[] to int[] //right now i do by a for loop
    > int[] to string //I donno how to do this
    > string to int[] //I donno how to do this
    >
    > Regards
    > Badri
    >
    >[/color]


    Comment

    • Badri Mohan

      #3
      Re: Data type conversion-Help

      Thanks Nicholas..

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:ubAMDCQuDH A.3532@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Badri,
      >
      > You can use the static Copy method on the Array class to do this.
      > However, it will not work in all cases. It will work for your second case
      > only. The reason it won't work for the others is as follows:
      >
      > 1 - You have the potential to lose information on the conversion of each
      > integer element to a byte element.
      > 3 - The Copy method doesn't know how to convert between an int and a[/color]
      string.[color=blue]
      > You have to loop through each element and do the conversion yourself.
      > 4 - The same as #3, but vice versa.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Badri Mohan" <bmohan@NOSPAMu ncc.edu> wrote in message
      > news:OG8NV5PuDH A.3496@TK2MSFTN GP11.phx.gbl...[color=green]
      > > Hi Guys
      > >
      > > I am tired of finding solution to this..
      > > Help me when u find time
      > >
      > > How to convert from
      > >
      > >
      > > int[] to byte[] //right now i do by a for loop
      > > byte[] to int[] //right now i do by a for loop
      > > int[] to string //I donno how to do this
      > > string to int[] //I donno how to do this
      > >
      > > Regards
      > > Badri
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...