Click here to Skip to main content
15,914,111 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to call 1 class method or constructor in other class ? Pin
musefan21-May-09 6:37
musefan21-May-09 6:37 
QuestionGet/Set for List<string> in C#</string> Pin
ipstefan21-May-09 3:07
ipstefan21-May-09 3:07 
AnswerRe: Get/Set for List in C# Pin
musefan21-May-09 3:12
musefan21-May-09 3:12 
GeneralRe: Get/Set for List in C# Pin
ipstefan21-May-09 3:15
ipstefan21-May-09 3:15 
GeneralRe: Get/Set for List in C# Pin
musefan21-May-09 3:20
musefan21-May-09 3:20 
AnswerRe: Get/Set for List in C# Pin
Anthony Mushrow21-May-09 3:18
professionalAnthony Mushrow21-May-09 3:18 
GeneralRe: Get/Set for List in C# Pin
ipstefan21-May-09 3:49
ipstefan21-May-09 3:49 
AnswerRe: Get/Set for List in C# Pin
Luc Pattyn21-May-09 3:36
sitebuilderLuc Pattyn21-May-09 3:36 
Hi,

you got it rather twisted. Basically what you have is:

1.
a base class DefCompareProperty which holds a list that you can add to, and get.

2.
a derived class DefComparing which inherits from DefCompareProperty, so it too holds the list DefCompareProperty is holding.

3. but then, inside the DefCompare method, you have the line DefCompareProperty df = new DefCompareProperty(); which adds a DefCompareProperty inside the DefComparing object (which is a DefCompareProperty itself), so now DefCompareProperty is actually holding two lists (until DefCompare method is done). Then you add items to the second list, and the method ends, so the second list no longer exists, and it all doesn't make much sense.


So, you are getting everyone confused by using very similar class names; also the SetDefComp() method is badly named, it should reallybe called add since it does not set anything, it adds something.

I would do things differently, something along these lines (not tested):
// a list of strings, we will use the List methods, no need to add any code
public class DefCompareProperty : List<string> {}

public class DefComparing:DefCompareProperty {
    public void DefCompare() {
        this.Clear(); // clear the list
        // doing something to the list here using this.Add(...)
    }
}

The main differences are:
1. my classes don't hold lists, they are lists.
2. I operate on the existing list, not on a new one.

Of course you could as well forego class DefCompareProperty and simply write public class DefComparing:List<string> {...}

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.

GeneralRe: Get/Set for List in C# Pin
musefan21-May-09 3:45
musefan21-May-09 3:45 
GeneralRe: Get/Set for List in C# Pin
PIEBALDconsult21-May-09 4:09
mvePIEBALDconsult21-May-09 4:09 
GeneralRe: Get/Set for List in C# Pin
Luc Pattyn21-May-09 4:21
sitebuilderLuc Pattyn21-May-09 4:21 
GeneralRe: Get/Set for List in C# Pin
musefan21-May-09 4:37
musefan21-May-09 4:37 
GeneralRe: Get/Set for List in C# Pin
Paddy Boyd21-May-09 5:24
Paddy Boyd21-May-09 5:24 
GeneralRe: Get/Set for List in C# Pin
Luc Pattyn21-May-09 5:30
sitebuilderLuc Pattyn21-May-09 5:30 
Questionexcel x-axis in Time format 00:00:00 using C# Pin
carnister21-May-09 2:49
carnister21-May-09 2:49 
QuestionSave to default program files folder Pin
Jon Henry21-May-09 2:30
Jon Henry21-May-09 2:30 
AnswerRe: Save to default program files folder Pin
musefan21-May-09 2:35
musefan21-May-09 2:35 
AnswerRe: Save to default program files folder [modified] Pin
Luc Pattyn21-May-09 3:41
sitebuilderLuc Pattyn21-May-09 3:41 
GeneralRe: Save to default program files folder Pin
Jon Henry21-May-09 13:00
Jon Henry21-May-09 13:00 
GeneralRe: Save to default program files folder Pin
Luc Pattyn21-May-09 13:35
sitebuilderLuc Pattyn21-May-09 13:35 
QuestionCurious question as I am c# developer. [modified] Pin
Blubbo21-May-09 2:23
Blubbo21-May-09 2:23 
AnswerRe: Curious question as I am c# developer. Pin
musefan21-May-09 2:33
musefan21-May-09 2:33 
AnswerRe: Curious question as I am c# developer. Pin
EliottA21-May-09 3:01
EliottA21-May-09 3:01 
JokeRe: Curious question as I am c# developer. Pin
Manas Bhardwaj21-May-09 4:02
professionalManas Bhardwaj21-May-09 4:02 
GeneralRe: Curious question as I am c# developer. Pin
PIEBALDconsult21-May-09 5:20
mvePIEBALDconsult21-May-09 5:20 

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.