0

I'm trying to understand why this delegate method has no value in the output. I thought it had to be: Value is - 5 Value is - 5

But the result is: Value is - Value is -

Why number "5" is absent is this example?

    class Program
{
    internal delegate void Feedback(Int32 value);
    static void Main(string[] args)
    {
        Feedback fbChain = null;
        Feedback delFeedback = new Feedback(Print);

        fbChain += delFeedback;
        fbChain += delFeedback;

        fbChain.Invoke(5);
    }

    internal static void Print(Int32 value)
    {
        Console.WriteLine("Value is - ", value);
    }       
}

2 Answers 2

2

Try this:

internal static void Print(Int32 value)
{
    Console.WriteLine("Value is - {0}", value);
}

(You left out the {0}, which is what tells Console.WriteLine to insert the second parameter into the output.)

Sign up to request clarification or add additional context in comments.

Comments

0

you can try these:

    internal static void Print(Int32 value)
{
    Console.WriteLine("Value is - " + value);
}

or

internal static void Print(Int32 value)
{

    Console.WriteLine(string.Format("Value is - {0}", value));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.