Click here to Skip to main content
15,908,906 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to return an environment variable? Pin
turbosupramk33-Dec-10 18:33
turbosupramk33-Dec-10 18:33 
GeneralRe: How to return an environment variable? Pin
Dr.Walt Fair, PE3-Dec-10 19:52
professionalDr.Walt Fair, PE3-Dec-10 19:52 
QuestionPrevent class member circular initialization? Pin
frattaro3-Dec-10 5:01
frattaro3-Dec-10 5:01 
AnswerRe: Prevent class member circular initialization? Pin
_Erik_3-Dec-10 5:22
_Erik_3-Dec-10 5:22 
AnswerRe: Prevent class member circular initialization? PinPopular
Luc Pattyn3-Dec-10 5:22
sitebuilderLuc Pattyn3-Dec-10 5:22 
GeneralRe: Prevent class member circular initialization? Pin
Dalek Dave3-Dec-10 5:33
professionalDalek Dave3-Dec-10 5:33 
GeneralRe: Prevent class member circular initialization? Pin
frattaro3-Dec-10 5:58
frattaro3-Dec-10 5:58 
GeneralRe: Prevent class member circular initialization? Pin
Luc Pattyn3-Dec-10 7:04
sitebuilderLuc Pattyn3-Dec-10 7:04 
While it is technically correct, it does prevent the infinite recursion, this is still not the right way to handle things.

1.
If you have a many-to-many relation like that, you should keep it outside both classes, i.e. the User class shouldn't automatically create or touch groups, and the Group class shouldn't create or touch users. You could give them a second constructor where a Group (or a User) is a parameter, basically saying "give me a new User and add him to this Group" for comfort, note this makes it all explicit.

2.
If you want a single list that contains all objects of some class, the best way to do it is with a static list burried inside the class; then you should add them automatically.

class User {
    private static List<User> users=new List<User>();

    public User() {
        users.Add(this);
    }
}


You may then add a property that gets a read-only copy of the list of users, so your app can look at it.

Warning: the list will grow; it will also remember User objects that no longer exist in your app, however by adding them to the list, they will never get collected. So you may want to use WeakReference instead; and maybe use a finalizer. etc.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.


AnswerRe: Prevent class member circular initialization? Pin
PIEBALDconsult4-Dec-10 10:00
mvePIEBALDconsult4-Dec-10 10:00 
QuestionDotNet ThreadPool not meant for long running jobs? Pin
devvvy2-Dec-10 23:51
devvvy2-Dec-10 23:51 
AnswerRe: DotNet ThreadPool not meant for long running jobs? PinPopular
Eddy Vluggen3-Dec-10 0:16
professionalEddy Vluggen3-Dec-10 0:16 
GeneralRe: DotNet ThreadPool not meant for long running jobs? Pin
Dalek Dave3-Dec-10 3:18
professionalDalek Dave3-Dec-10 3:18 
GeneralRe: DotNet ThreadPool not meant for long running jobs? Pin
Eddy Vluggen3-Dec-10 6:48
professionalEddy Vluggen3-Dec-10 6:48 
AnswerRe: DotNet ThreadPool not meant for long running jobs? Pin
Keith Barrow3-Dec-10 0:21
professionalKeith Barrow3-Dec-10 0:21 
GeneralRe: DotNet ThreadPool not meant for long running jobs? Pin
devvvy3-Dec-10 15:20
devvvy3-Dec-10 15:20 
GeneralRe: DotNet ThreadPool not meant for long running jobs? [modified] Pin
Keith Barrow3-Dec-10 21:46
professionalKeith Barrow3-Dec-10 21:46 
GeneralThank you guys Pin
devvvy4-Dec-10 13:54
devvvy4-Dec-10 13:54 
AnswerRe: DotNet ThreadPool not meant for long running jobs? Pin
#realJSOP3-Dec-10 4:06
professional#realJSOP3-Dec-10 4:06 
AnswerRe: DotNet ThreadPool not meant for long running jobs? [modified] Pin
Luc Pattyn3-Dec-10 17:05
sitebuilderLuc Pattyn3-Dec-10 17:05 
AnswerRe: DotNet ThreadPool not meant for long running jobs? Pin
Pete O'Hanlon3-Dec-10 20:56
mvePete O'Hanlon3-Dec-10 20:56 
QuestionCorordinate problem when load the image in picture box in zoom mode Pin
Nivas822-Dec-10 22:10
Nivas822-Dec-10 22:10 
AnswerRe: Corordinate problem when load the image in picture box in zoom mode Pin
Luc Pattyn3-Dec-10 0:51
sitebuilderLuc Pattyn3-Dec-10 0:51 
QuestionNeeded to Create a Scrolling Ticker with LinkLabel Functionality Pin
honeyashu2-Dec-10 20:04
honeyashu2-Dec-10 20:04 
AnswerRe: Needed to Create a Scrolling Ticker with LinkLabel Functionality Pin
Jacob D Dixon4-Dec-10 3:23
Jacob D Dixon4-Dec-10 3:23 
QuestionListView in C#.net Pin
mathy2-Dec-10 19:52
mathy2-Dec-10 19:52 

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.