array size problem

  • Thread starter Thread starter jayson_13
  • Start date Start date
J

jayson_13

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[cmbSubCatCategoryID.SelectedIndex];
}

How can i achieve this?
Thanks!
 
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,
 
Back
Top