Skip to main content

Csharp Events basics


Events in C#

Syntax of event declaration
[attributes][modifers] event <delegate_type> <event_name>[ {event body}   ];


we will discuses about syntax of event


·        Attributes are csharp attributes
·        Modifiers are optional and those may one are combination of more than one
o   Accessing specifies
§  Public, private, protected, internal
§  New, Virtual, Abstract, override
§  Static ,extern
o   Event will work between objects because of that when your are defining event in main function existing class you have to specifies event as static             
·        Event
o   It is a keyword used to give event declaration
o   In syntax event keyword must not be omitted
·        Type
o   Event is a role player  variable foe delegate
o   Without delegate event will not fired
o   Type is a delegate type which is giving functions to event at run time when event is fired this process is known as hookup
·        Event name
o   It is identifiers or event variable name
o   It must be unique in program
·        Accessor _declaration
o   When programmer want add or remove  functionalities to a particular events ,specification will be done in body
o   We can do two way
o   With add and remove


using System;

namespace eventdemo1

{
    public delegate void eventdel();
   
    class Program
    {
        public static event eventdel myevent;

        public static void eventfire_switch() { myevent.Invoke(); }


        public static void f (){ Console.WriteLine("i was fired by myevent");}

        public static void f2() { Console.WriteLine("i was added and removed at 2 fired event by myevent"); }
        static void Main(string[] args)
        {
            myevent += new eventdel(f);
            myevent += new eventdel(f2);
            eventfire_switch();
         
        }
    }
}


FAQS

  1. what is event in chsharp
  2. what is difference between events and delegates in chsharp
  3. syntax for event in chsharp
  4. what is type of events in chsharp
  5. can i write static events in csharp
  6. list out attributes of events in chsharp
thank you

Comments

Popular posts from this blog

OOPS-Constructors and distractor

Hi friends today we will discussed about constructors and distractor in csharp Constructors are used to memory allocation for real world entities which are created with the help of objects. When program or application is running, application required memory to save and manipulate data of that real world object/entities. Now the question is how much memory is required for that object? Frankly no one can decide how much memory is required for that application because of that all object oriented programming languages depends on heap memory. Heap memory is a logical memory in RAM (temporary memory) and size is logically infinity (physically it is limited).This memory has to be creating at run time when we are using object in our program/application. Now we have to know that what type of data members we have in object. In object we have two types of data members’ object instance  shared instance Object instance are allocated occupies object memory and eve

FAQS PART 3

data integrity depends on data sharing accuracy  redundency 2&4                              ANS: accuracy which is lightweight protocal?         ANS:soap class is which based memory      ANS: Heap  csharp code is                          ANS: managed sn.exe generates what?             ANS: Strong Name file and fileinfo classes doesn't offer the set of functionality moving creating copying  deleting                                   ANS: Creating datareader field count return type        ANS: integer type dataset and untype dataset difference? type dataset have schema information of database(primary key and FK info) untype does not have schema information GOALS OF INTEROPERABILITY ANSWER net does not affect existing COM objects .Net and COM components interoperate with each other COM components can be upgraded into .NET components if u build the application what file with extension generated                   ANS: .exe null is a string ?