Click here to Skip to main content
15,892,746 members
Home / Discussions / C#
   

C#

 
Questionkeyboard sequence Pin
quasi478523-Jan-06 11:54
quasi478523-Jan-06 11:54 
QuestionTurn of word wrapping on labels Pin
dbrenth23-Jan-06 10:52
dbrenth23-Jan-06 10:52 
AnswerRe: Turn of word wrapping on labels Pin
tarasn23-Jan-06 11:42
tarasn23-Jan-06 11:42 
AnswerRe: Turn of word wrapping on labels Pin
microsoc23-Jan-06 15:15
microsoc23-Jan-06 15:15 
AnswerRe: Turn of word wrapping on labels Pin
Dan Neely24-Jan-06 2:08
Dan Neely24-Jan-06 2:08 
GeneralRe: Turn of word wrapping on labels Pin
dbrenth24-Jan-06 5:29
dbrenth24-Jan-06 5:29 
Questionclass question Pin
Manu_8123-Jan-06 10:44
Manu_8123-Jan-06 10:44 
AnswerRe: class question Pin
Colin Angus Mackay23-Jan-06 11:22
Colin Angus Mackay23-Jan-06 11:22 
Manu_81 wrote:
I want to create an array of the above class to store different values in MonNumber and EDID_Info, so that I can access those values in other calsses where ever I want


First, if you declare the fields as static you will only get one for all instances of the class. So, if you want to create multiple instances of the class you cannot create these as static for the purpose you want.

Second, declaring a field as public is bad form. You should declare them as private or protected and access them through properties. Read this article if you want to know why you should make the fields private and access them through a public property[^]

Finally, you can make the array global by adding it as a static field to the class (because you only want one instance of the array made available globally across your application (right?)

So your class will look something like this:
public class NewMonitorDetails
{
    // The static array of all NewMonitorDetails objects to be made available globally
    private static ArrayList newMonitorDetailsArray = new ArrayList();
 
    // The instance fields (I corrected the names to fit the .NET naming guidelines)
    private int monNumber;
    private string edid_Info; 
 
    // An empty constructor - not strictly required as the compiler will create
    // a default empty constructor for you.
    public NewMonitorDetails()
    {
    }
 
    //  public property backing the private field.
    public int MonNumber
    {
        get { return this.monNumber; }
        set { this.monNumber = value; }
    }
 
    //  public property backing the private field.
    public string EDID_Info
    {
        get { return this.edid_Info; }
        set { this.edid_Info = value; }
    }
 
    //  public property backing the private field.
    public static ArrayList NewMonitorDetailsArray
    {
        get { return NewMonitorDetails.newMonitorDetailsArray; }
        // No setter required - you can just modify the existing array
        // rather than create a new one.
    }
}


Does this help?

ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell


-- modified at 4:19 Tuesday 24th January, 2006

GeneralRe: class question Pin
Manu_8123-Jan-06 12:09
Manu_8123-Jan-06 12:09 
GeneralRe: class question Pin
Colin Angus Mackay23-Jan-06 22:19
Colin Angus Mackay23-Jan-06 22:19 
GeneralRe: class question Pin
Colin Angus Mackay23-Jan-06 22:23
Colin Angus Mackay23-Jan-06 22:23 
AnswerRe: class question Pin
Guffa23-Jan-06 11:26
Guffa23-Jan-06 11:26 
Questionobject[] initialization as a parameter Pin
clintsinger23-Jan-06 10:30
clintsinger23-Jan-06 10:30 
AnswerRe: object[] initialization as a parameter Pin
Andy Moore23-Jan-06 11:01
Andy Moore23-Jan-06 11:01 
GeneralRe: object[] initialization as a parameter Pin
clintsinger23-Jan-06 11:06
clintsinger23-Jan-06 11:06 
QuestionProblem with Textbox Scrollbar Pin
Wouter Neuteboom23-Jan-06 10:14
Wouter Neuteboom23-Jan-06 10:14 
AnswerRe: Problem with Textbox Scrollbar Pin
microsoc23-Jan-06 15:20
microsoc23-Jan-06 15:20 
GeneralRe: Problem with Textbox Scrollbar Pin
Wouter Neuteboom24-Jan-06 0:36
Wouter Neuteboom24-Jan-06 0:36 
GeneralRe: Problem with Textbox Scrollbar Pin
Wouter Neuteboom24-Jan-06 2:22
Wouter Neuteboom24-Jan-06 2:22 
AnswerRe: Problem with Textbox Scrollbar Pin
microsoc24-Jan-06 14:40
microsoc24-Jan-06 14:40 
Questionadding a flash file to the form Pin
Manu_8123-Jan-06 8:10
Manu_8123-Jan-06 8:10 
AnswerRe: adding a flash file to the form Pin
tarasn23-Jan-06 10:43
tarasn23-Jan-06 10:43 
GeneralRe: adding a flash file to the form Pin
Manu_8123-Jan-06 12:12
Manu_8123-Jan-06 12:12 
AnswerRe: adding a flash file to the form Pin
mitooki24-Jan-06 4:16
mitooki24-Jan-06 4:16 
QuestionGetting Selected text in webbrowser control Pin
emran83423-Jan-06 7:34
emran83423-Jan-06 7:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.