Click here to Skip to main content
15,925,602 members
Home / Discussions / C#
   

C#

 
AnswerRe: Graphic - Exact string sizes Pin
J. Dunlap11-Jun-07 13:13
J. Dunlap11-Jun-07 13:13 
QuestionEvent Firing Pin
tobriain11-Jun-07 8:13
tobriain11-Jun-07 8:13 
AnswerRe: Event Firing Pin
Luc Pattyn11-Jun-07 9:15
sitebuilderLuc Pattyn11-Jun-07 9:15 
GeneralRe: Event Firing Pin
tobriain11-Jun-07 10:11
tobriain11-Jun-07 10:11 
GeneralRe: Event Firing Pin
Luc Pattyn11-Jun-07 10:36
sitebuilderLuc Pattyn11-Jun-07 10:36 
GeneralRe: Event Firing Pin
Leslie Sanford11-Jun-07 10:53
Leslie Sanford11-Jun-07 10:53 
GeneralRe: Event Firing Pin
tobriain11-Jun-07 11:21
tobriain11-Jun-07 11:21 
GeneralRe: Event Firing Pin
Leslie Sanford11-Jun-07 12:03
Leslie Sanford11-Jun-07 12:03 
I'm taking a shot in the dark here because I still may not completely understand your problem. However, that's never stopped me in the past. Smile | :)

I would keep a collection of objects for each ID. Actually, a list of lists would be appropriate here. Then I'd use a switch statement or a string of if/else statements to update the objects when you receive a notification:

public MyObject
{
    objectList = List<List<UpdateableObject>>();
 
    objectList.Add(new List<UpdateableObject>());
    objectList[0].Add(new UpdateableObject()); // ID: 0
    objectList[0].Add(new UpdateableObject()); // ID: 0
 
    objectList.Add(new List<UpdateableObject>());
    objectList[1].Add(new UpdateableObject()); // ID: 1
    objectList[1].Add(new UpdateableObject()); // ID: 1
 
    // And so on...
}
  
public void Notify()
{
    Update[] updates = GetUpdates();
 
    for(int i = 0; i < updates.Length; i++)
    {
        if(updates[i].ID == 0)
        {
            foreach(UpdateableObject obj in objectList[0])
            {
                obj.Value = updates[i].Value;
            }
        }
        else if(updates[i].ID == 1)
        {
            foreach(UpdateableObject obj in objectList[1])
            {
                obj.Value = updates[i].Value;
            }
        }
    }
}


In this case, I'm assuming the ID's are consecutive integers, but the code above doesn't depend on that. The ID's could be anything. If you have a lot of ID's you will have a long string of if/else if statements. But as long as this is isolated to a single place in your code, I wouldn't worry about it.

You can have variations on this by storing the list of updateable objects in a hashtable, as you've mentioned, by the ID. Or use an array of delegates like Luc suggested. I wouldn't create 20+ events that you trigger yourself, though. I think that would be the least efficient way to go. Just my opinion.
QuestionActive Directory - logonhours Pin
Runtorious11-Jun-07 8:06
Runtorious11-Jun-07 8:06 
QuestionDatagrid rows Pin
md_refay11-Jun-07 7:58
md_refay11-Jun-07 7:58 
QuestionCPU load for spesific proccess Pin
crash89311-Jun-07 7:58
crash89311-Jun-07 7:58 
AnswerRe: CPU load for spesific proccess Pin
Luc Pattyn11-Jun-07 8:07
sitebuilderLuc Pattyn11-Jun-07 8:07 
GeneralRe: CPU load for spesific proccess Pin
crash89311-Jun-07 15:31
crash89311-Jun-07 15:31 
Question.NET documentor Pin
HexaDeveloper11-Jun-07 5:35
HexaDeveloper11-Jun-07 5:35 
AnswerRe: .NET documentor Pin
Joseph Guadagno11-Jun-07 16:32
Joseph Guadagno11-Jun-07 16:32 
Questiontransparent background Pin
bDreea11-Jun-07 4:22
bDreea11-Jun-07 4:22 
AnswerRe: transparent background Pin
Hesham Yassin11-Jun-07 6:35
Hesham Yassin11-Jun-07 6:35 
QuestionHow add multiple icons Pin
Mark F.11-Jun-07 4:03
Mark F.11-Jun-07 4:03 
AnswerRe: How add multiple icons Pin
Giorgi Dalakishvili11-Jun-07 4:05
mentorGiorgi Dalakishvili11-Jun-07 4:05 
GeneralRe: How add multiple icons Pin
Mark F.11-Jun-07 4:23
Mark F.11-Jun-07 4:23 
GeneralRe: How add multiple icons Pin
Giorgi Dalakishvili11-Jun-07 4:44
mentorGiorgi Dalakishvili11-Jun-07 4:44 
GeneralRe: How add multiple icons Pin
Not Active11-Jun-07 4:51
mentorNot Active11-Jun-07 4:51 
AnswerRe: How add multiple icons Pin
Squeaker11-Jun-07 5:18
Squeaker11-Jun-07 5:18 
QuestionHow to keep a progress bar running when the form is busy with some file operation Pin
d_sinha11-Jun-07 3:57
d_sinha11-Jun-07 3:57 
AnswerRe: How to keep a progress bar running when the form is busy with some file operation Pin
Giorgi Dalakishvili11-Jun-07 4:01
mentorGiorgi Dalakishvili11-Jun-07 4:01 

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.