Casting Object into string[ ]?(Repost)

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

    #1

    Casting Object into string[ ]?(Repost)

    Hi:

    Here's what I am trying to do, pass a string array between
    two pages using Server.Transfer method:
    Sending page I do this:
    private string[] arrFCInfo=new String[5];
    //Property - read only public
    public object arrayFC
    {
    get
    {
    return arrFCInfo;
    }
    }

    In the receiving page, I want to get the string array from
    the object.

    My basic question: How do I cast an object in to a string
    []?

    Thanks in advance.



  • Juan Gabriel Del Cid

    #2
    Re: Casting Object into string[ ]?(Repost)

    > My basic question:[color=blue]
    > How do I cast an object into a string []?[/color]

    Have you tried this:

    string []arr = (string [])theObject;

    That should work,
    -JG


    Comment

    • Eric Cadwell

      #3
      Re: Casting Object into string[ ]?(Repost)

      To cast to a string[] simply cast it. string[] var = (string[])obj.arrayFC;

      Or try the as syntax, it's a little more graceful than a try-catch block
      should you need it.

      string[] var = obj.arrayFC as string[];
      if (var != null)
      {
      // do something
      }


      HTH;
      Eric Cadwell



      "Nathan" <anonymous@disc ussions.microso ft.com> wrote in message
      news:053801c398 ed$0a7c3850$a30 1280a@phx.gbl.. .[color=blue]
      > Hi:
      >
      > Here's what I am trying to do, pass a string array between
      > two pages using Server.Transfer method:
      > Sending page I do this:
      > private string[] arrFCInfo=new String[5];
      > //Property - read only public
      > public object arrayFC
      > {
      > get
      > {
      > return arrFCInfo;
      > }
      > }
      >
      > In the receiving page, I want to get the string array from
      > the object.
      >
      > My basic question: How do I cast an object in to a string
      > []?
      >
      > Thanks in advance.
      >
      >
      >[/color]


      Comment

      • Peter Koen

        #4
        Re: Casting Object into string[ ]?(Repost)

        "Nathan" <anonymous@disc ussions.microso ft.com> wrote in news:053801c398 ed
        $0a7c3850$a3012 80a@phx.gbl:
        [color=blue]
        > Hi:
        >
        > Here's what I am trying to do, pass a string array between
        > two pages using Server.Transfer method:
        > Sending page I do this:
        > private string[] arrFCInfo=new String[5];
        > //Property - read only public
        > public object arrayFC
        > {
        > get
        > {
        > return arrFCInfo;
        > }
        > }
        >
        > In the receiving page, I want to get the string array from
        > the object.
        >
        > My basic question: How do I cast an object in to a string
        > []?
        >
        > Thanks in advance.
        >
        >
        >
        >[/color]

        string[] something = new string[5];

        object obj = (object)somethi ng;

        string[] anotherthing = (string[])obj;

        --
        best regards

        Peter Koen
        -----------------------------------
        MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS

        Comment

        Working...