Click here to Skip to main content
15,885,366 members
Home / Discussions / C#
   

C#

 
Questioncustom control textbox with a label tied Pin
Wendell.S31-May-09 16:21
Wendell.S31-May-09 16:21 
AnswerRe: custom control textbox with a label tied Pin
Dave Kreskowiak31-May-09 17:28
mveDave Kreskowiak31-May-09 17:28 
QuestionUltra-light native embedded database Pin
Pascal Ganaye31-May-09 10:27
Pascal Ganaye31-May-09 10:27 
AnswerRe: Ultra-light native embedded database Pin
Henry Minute31-May-09 11:07
Henry Minute31-May-09 11:07 
AnswerRe: Ultra-light native embedded database Pin
Garth J Lancaster31-May-09 12:02
professionalGarth J Lancaster31-May-09 12:02 
AnswerRe: Ultra-light native embedded database Pin
Joe Woodbury31-May-09 16:14
professionalJoe Woodbury31-May-09 16:14 
AnswerRe: Ultra-light native embedded database Pin
Pascal Ganaye1-Jun-09 13:41
Pascal Ganaye1-Jun-09 13:41 
Questionauto initialise all public fields in a class Pin
tig281031-May-09 10:09
tig281031-May-09 10:09 
Hi all

I’m looking for some assientance on auto initialising all public fields in a class.

I have a class with about 50+ fields. When an instance of the class is created and a value is assigned to the fields, it appends to the existing static value.

MyClass obj = new MyClass();
obj.Example = “THIS_STRING”; // This would therefore return STATIC_BEGINING_OF_STRINGTHIS_STRING which is desired.

My problem is that in obj.allRecords will only contain “STATIC_BEGINING_OF_STRINGTHIS_ STRING” and not “ANOTHER_STATIC_BEGINING_OF_STRING” plus the other 50 fields as they have not been initialised to their initial default value. I dont want to do it manually in the object as the point is that they are in the list as their default value even if unchanged.

Thanks for any help.

    class MyClass    {

        public MyClass() { }

        public List<string> allRecords = new List<string>();
        
        private string  _example = "STATIC_BEGINING_OF_STRING"; 
        public string Example
        {
            get { return _example; }
            set 
            {
                _example += value; 
                allRecords.Add(_example); 
            }
        }

// 50 more encapsulated fields

        private string _recordEnd = "ANOTHER_STATIC_BEGINING_OF_STRING";
        public string RecordEnd
        {
            get { return _recordEnd; }
            set 
            {
                _recordEnd += value;
                allRecords.Add(_recordEnd);
            }
        }
   }

AnswerRe: auto initialise all public fields in a class Pin
Henry Minute31-May-09 11:21
Henry Minute31-May-09 11:21 
GeneralRe: auto initialise all public fields in a class Pin
tig281031-May-09 11:29
tig281031-May-09 11:29 
GeneralRe: auto initialise all public fields in a class Pin
Henry Minute31-May-09 11:42
Henry Minute31-May-09 11:42 
GeneralRe: auto initialise all public fields in a class Pin
tig281031-May-09 14:02
tig281031-May-09 14:02 
AnswerRe: auto initialise all public fields in a class Pin
S. Senthil Kumar31-May-09 21:11
S. Senthil Kumar31-May-09 21:11 
Questioneditable datagrid Pin
hamadam2131-May-09 8:21
hamadam2131-May-09 8:21 
AnswerRe: editable datagrid [modified] Pin
dan!sh 31-May-09 8:36
professional dan!sh 31-May-09 8:36 
AnswerRe: editable datagrid Pin
Satish Pai31-May-09 20:26
Satish Pai31-May-09 20:26 
QuestionParallel Port Polling Pin
GlenET31-May-09 4:31
GlenET31-May-09 4:31 
AnswerRe: Parallel Port Polling Pin
0x3c031-May-09 5:30
0x3c031-May-09 5:30 
GeneralRe: Parallel Port Polling Pin
GlenET31-May-09 6:31
GlenET31-May-09 6:31 
GeneralRe: Parallel Port Polling Pin
0x3c031-May-09 7:00
0x3c031-May-09 7:00 
GeneralRe: Parallel Port Polling Pin
GlenET5-Jun-09 6:31
GlenET5-Jun-09 6:31 
QuestionConverting math equations to C# Pin
livewirerules31-May-09 4:13
livewirerules31-May-09 4:13 
AnswerRe: Converting math equations to C# Pin
harold aptroot31-May-09 4:28
harold aptroot31-May-09 4:28 
GeneralRe: Converting math equations to C# Pin
livewirerules31-May-09 4:35
livewirerules31-May-09 4:35 
GeneralRe: Converting math equations to C# Pin
molesworth31-May-09 6:40
molesworth31-May-09 6:40 

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.