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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top