Scope of class data

H

Hoop

Hi,
I have a class that I make an array of in the app, like,

//create an array of Module's
public Modules[] aModule = new Modules[16];

This class has a few pieces of data that have the same value. Right
now I have set the data up as properties,
and read them like,
module[moduleIDIndex].NumOfInputs;
via an index.
Since the NumOfInputs is constant from module to module I would like
to drop out the array index
and just acess the data,
module.NumOfInputs. I do not want to make this static since there
might not be any instances of this
module.
Is there a way to do this, or maybe as a property access is the best
way?
Thanks
Jeff
 
J

Jon Skeet [C# MVP]

Hoop said:
I have a class that I make an array of in the app, like,

//create an array of Module's
public Modules[] aModule = new Modules[16];

This class has a few pieces of data that have the same value. Right
now I have set the data up as properties,
and read them like,
module[moduleIDIndex].NumOfInputs;
via an index.
Since the NumOfInputs is constant from module to module I would like
to drop out the array index
and just acess the data,
module.NumOfInputs. I do not want to make this static since there
might not be any instances of this
module.
Is there a way to do this, or maybe as a property access is the best
way?

You should make it static precisely *because* there might not be any
instances of Module, unless I've mistaken the intention.

Assuming "NumOfInputs" is fixed for all modules, it should be static.
 
H

Hoop

Hoop said:
I have a class that I make an array of in the app, like,
//create an array of Module's
public Modules[] aModule = new Modules[16];
This class has a few pieces of data that have the same value. Right
now I have set the data up as properties,
and read them like,
module[moduleIDIndex].NumOfInputs;
via an index.
Since the NumOfInputs is constant from module to module I would like
to drop out the array index
and just acess the data,
module.NumOfInputs. I do not want to make this static since there
might not be any instances of this
module.
Is there a way to do this, or maybe as a property access is the best
way?

You should make it static precisely *because* there might not be any
instances of Module, unless I've mistaken the intention.

Assuming "NumOfInputs" is fixed for all modules, it should be static.

--
Jon Skeet - <[email protected]>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
World class .NET training in the UK:http://iterativetraining.co.uk- Hide quoted text -

- Show quoted text -

Hi Jon,
Yes it is fixed. You are correct there might not or might be an
instance of the module.
I will go with the static.
Thanks
Jeff
 

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

Top