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

C#

 
GeneralRe: File transfer in C# Pin
EliottA24-Jan-09 5:49
EliottA24-Jan-09 5:49 
GeneralRe: File transfer in C# Pin
SimpleData24-Jan-09 5:52
SimpleData24-Jan-09 5:52 
GeneralRe: File transfer in C# Pin
#realJSOP24-Jan-09 8:46
mve#realJSOP24-Jan-09 8:46 
QuestionSecurity Information Internet Pin
trinm198724-Jan-09 4:14
trinm198724-Jan-09 4:14 
AnswerRe: Security Information Internet Pin
Wendelius24-Jan-09 4:45
mentorWendelius24-Jan-09 4:45 
GeneralRe: Security Information Internet Pin
trinm198724-Jan-09 5:04
trinm198724-Jan-09 5:04 
GeneralRe: Security Information Internet Pin
Dave Kreskowiak24-Jan-09 10:27
mveDave Kreskowiak24-Jan-09 10:27 
Questiondelegates and events Pin
staticv24-Jan-09 3:23
staticv24-Jan-09 3:23 
// Holds the arguments for the StatusChanged event

public class StatusChangedEventArgs : EventArgs

{

    // The argument we're interested in is a message describing the event

    private string EventMsg;

 

    // Property for retrieving and setting the event message

    public string EventMessage

    {

        get

        {

            return EventMsg;

        }

        set

        {

            EventMsg = value;

        }

    }

 

    // Constructor for setting the event message

    public StatusChangedEventArgs(string strEventMsg)

    {

        EventMsg = strEventMsg;

    }

}

// This delegate is needed to specify the parameters we're passing with our event
public delegate void StatusChangedEventHandler(object sender, StatusChangedEventArgs e);


public static event StatusChangedEventHandler StatusChanged;

Okay, so in the above code, we created a delegate and a custom event.

// This is called when we want to raise the StatusChanged event

public static void OnStatusChanged(StatusChangedEventArgs e)

{

    StatusChangedEventHandler statusHandler = StatusChanged;

    if (statusHandler != null)

    {

        // Invoke the delegate

        statusHandler(null, e);

    }

}


What does the bold line do? Why do we check for null?


EDIT: The code is from C# Chat: Part 2 - Building the Chat Server (C# Programming Tutorial) • Geekpedia[^] check that out, if the above code doesn't provides what I mean.

Top Web Hosting Providers[^]

Do, or do not. There is no 'try'.

AnswerRe: delegates and events [modified] Pin
Luc Pattyn24-Jan-09 3:29
sitebuilderLuc Pattyn24-Jan-09 3:29 
GeneralRe: delegates and events Pin
staticv24-Jan-09 4:36
staticv24-Jan-09 4:36 
AnswerRe: delegates and events [modified] Pin
Luc Pattyn24-Jan-09 4:54
sitebuilderLuc Pattyn24-Jan-09 4:54 
GeneralRe: delegates and events Pin
staticv24-Jan-09 5:01
staticv24-Jan-09 5:01 
GeneralRe: delegates and events Pin
jkohler24-Jan-09 4:51
jkohler24-Jan-09 4:51 
AnswerRe: delegates and events [modified] Pin
Luc Pattyn24-Jan-09 5:09
sitebuilderLuc Pattyn24-Jan-09 5:09 
GeneralRe: delegates and events Pin
jkohler24-Jan-09 6:48
jkohler24-Jan-09 6:48 
AnswerRe: delegates and events Pin
DaveyM6924-Jan-09 4:13
professionalDaveyM6924-Jan-09 4:13 
GeneralRe: delegates and events Pin
Luc Pattyn24-Jan-09 4:54
sitebuilderLuc Pattyn24-Jan-09 4:54 
AnswerRe: delegates and events Pin
Giorgi Dalakishvili24-Jan-09 4:41
mentorGiorgi Dalakishvili24-Jan-09 4:41 
QuestionUsing A Retrieved Type Pin
#realJSOP24-Jan-09 2:24
mve#realJSOP24-Jan-09 2:24 
AnswerRe: Using A Retrieved Type Pin
User 665824-Jan-09 2:27
User 665824-Jan-09 2:27 
GeneralRe: Using A Retrieved Type Pin
#realJSOP24-Jan-09 2:28
mve#realJSOP24-Jan-09 2:28 
GeneralRe: Using A Retrieved Type Pin
User 665824-Jan-09 2:36
User 665824-Jan-09 2:36 
AnswerRe: Using A Retrieved Type Pin
DaveyM6924-Jan-09 2:35
professionalDaveyM6924-Jan-09 2:35 
GeneralRe: Using A Retrieved Type Pin
User 665824-Jan-09 2:39
User 665824-Jan-09 2:39 
GeneralRe: Using A Retrieved Type Pin
DaveyM6924-Jan-09 2:48
professionalDaveyM6924-Jan-09 2:48 

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.