array size problem

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

    #1

    array size problem

    hi,

    I want to create a public array that can be accessible through the
    same class. But the problem is the size of that array is unknown until
    some method in the same class has been called.
    How can i do it?

    private int[] CategoryID;

    private void FillDataSet()
    {
    ...
    int[] CategoryID = new int[dataset1.Tables[0].Rows.Count];
    }

    private void InsertData
    {
    Cmd.Parameters. Add(new OdbcParameter(" pCatID", OdbcType.Int,
    5)).Value = CategoryID[cmbSubCatCatego ryID.SelectedIn dex];
    }

    How can i achieve this?
    Thanks!
  • Franz

    #2
    Re: array size problem

    Use the Length property to get the size of the Array.

    --
    Franz Wong
    My C++ and C# Site (Traditional Chinese) : http://www.franzwong.com


    "jayson_13" <jayson_13@yaho o.com> ¦b¶l¥ó
    news:856e7de4.0 309300158.1bf46 cb7@posting.goo gle.com ¤¤¼¶¼g...[color=blue]
    > hi,
    >
    > I want to create a public array that can be accessible through the
    > same class. But the problem is the size of that array is unknown until
    > some method in the same class has been called.
    > How can i do it?
    >
    > private int[] CategoryID;
    >
    > private void FillDataSet()
    > {
    > ...
    > int[] CategoryID = new int[dataset1.Tables[0].Rows.Count];
    > }
    >
    > private void InsertData
    > {
    > Cmd.Parameters. Add(new OdbcParameter(" pCatID", OdbcType.Int,
    > 5)).Value = CategoryID[cmbSubCatCatego ryID.SelectedIn dex];
    > }
    >
    > How can i achieve this?
    > Thanks![/color]


    Comment

    • Ignacio Machin

      #3
      Re: array size problem

      Hi Jayson,


      Piece of cake , make your array private, accesible only through a property
      and in the get call the method :

      class A{
      private int [] categoryid=null ;

      public int[] CategoryID{
      get
      {
      if ( categoryid == null)
      FillDataSet();
      return categoryid;
      }
      }

      Hope this help,

      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation

      "jayson_13" <jayson_13@yaho o.com> wrote in message
      news:856e7de4.0 309300158.1bf46 cb7@posting.goo gle.com...[color=blue]
      > hi,
      >
      > I want to create a public array that can be accessible through the
      > same class. But the problem is the size of that array is unknown until
      > some method in the same class has been called.
      > How can i do it?
      >
      > private int[] CategoryID;
      >
      > private void FillDataSet()
      > {
      > ...
      > int[] CategoryID = new int[dataset1.Tables[0].Rows.Count];
      > }
      >
      > private void InsertData
      > {
      > Cmd.Parameters. Add(new OdbcParameter(" pCatID", OdbcType.Int,
      > 5)).Value = CategoryID[cmbSubCatCatego ryID.SelectedIn dex];
      > }
      >
      > How can i achieve this?
      > Thanks![/color]


      Comment

      Working...