C#.NET Multiple choices


Total available count: 28
Subject - Microsoft Technologies
Subsubject - C#.NET

Which of the below is not a built-in delegate?


 

 

 

 



B


Solution:-

Delegate gives a name to a method signature. Delegates allow or permit methods to be passed as parameters. Delegates can be used to define callback methods. Delegates can be chained together; for example, multiple methods can be called on a single event.

Example:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace event_programming
{
  //This is Subscriber Class
  class Program
  {
    static void Main(string[] args)
    {
      AddTwoNumbers a = new AddTwoNumbers();
      //Event gets binded with delegates
      a.ev_OddNumber += EventMessage;
      a.Add();
      Console.Read();
    }   
    //Delegates calls this method when the event raised. 
    static void EventMessage(object sender, EventArgs e)
    {
      Console.WriteLine("***Event Executed : This is Odd Number***");      
    }
  }
  //This is Publisher Class
  class AddTwoNumbers
  {
    public event EventHandler<EventArgs> ev_OddNumber;

    public void Add()
    {
      int result;
      result = 5 + 4;
      Console.WriteLine(result.ToString());
      //Check if result is odd number then raise event
      if((result % 2 != 0) && (ev_OddNumber != null))
      {
       ev_OddNumber(this, EventArgs.Empty); //Raised Event
      }     
    }
  }
}

In .NET, Func, Action, and Predicate types are built-in generic delegates that should be used for most common delegates instead of creating new custom delegates.




Next 5 multiple choice(s)

1

Which of the below is not a way to return multiple values?

2

How to print currency value in C#.Net?

3

Which of the following declaration is wrong?

4

How to use a keyword as an identifier?

5

Which of the following access modifier added in C# 7.2?

Comments