.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> .NET Framework >> Post New Question Subscribe to Interview Questions

What are the event's access modifiers ?

Posted By :Maverick     Posted Date :July 26, 2011    Points :40   Category :.NET Framework 
Event's are always public can be used where ever registered. But we can have access modifiers in events.Wecan have events with protected keyword which will be accessible only to inherited classes.We can have private events only for that class.

You can also find related Interview Question to What are the event's access modifiers ?  below: 

Explain about public and protected Access Modifiers?

  
Public:

public is an access modifier for types and type members. This is the most permissive access level as there are no restrictions on accessing a public type or type member.

protected:

protected is an access modifier for type members only. A protected member is only accessible within the body of the containing type and from within any classes derived from the containing type (More...)

Explain about private and internal Access Modifiers?

  
Private:
========
private is an access modifier for type members only. private access is the least accessible and such members are only accessible within the body of the containing type.
Note that nested types within the same containing body can also access those private members.

Internal:
--------
internal is an access modifier for types and type members. internal members are accessible only within file of the same assembly. It is an error to reference an internal type or internal type member outside the assembly within which it was declared.

A common use of internal access is in component-based development because it enables a group of components to interact in a private matter without being exposed to the outer world. For example, a Data Access Layer could have several classes with internal members that are only used by the DAL.
(More...)

What are class access modifiers ?

  
Access modifiers are keywords used to specify the declared accessibility of a member or a type. This section introduces the four access modifiers:
. Public - Access is not restricted.
. Protected - Access is limited to the containing class or types derived from the containing class.
. Internal - Access is limited to the current assembly.
. Protected inertnal - Access is limited to the current assembly or types derived . from the containing class.
. Private - Access is limited to the containing type.
(More...)

What is the Difference between Internal and Protected Internal Access Modifiers?

  
Internal :

It can be accessed by any code in the same assembly but cannot be accessable in another assembly

Protected Internal :

It can be accessed by any code in the same assembly, or by any derived class in another assembly. For a particular project. (More...)

What are Access Modifiers

  
Public - Access to same assembly or another assembly that references it.

Private - Access to same class or struct.

Protected - Access to same class or struct, or in a class that is derived.

Internal - Access to any code in the same assembly, but not from another assembly.

Protected Internal - Access to any code in the assembly in which it is declared, or from within a derived class in another assembly.
(More...)

How many Access Modifiers in JAVA?

  
It's having Three Access Modifiers.
1.Private
2.Public
3.Protected
(More...)

How many Access Modifiers in C# or ASP.Net?

  
It's having Four Access Modifiers.
1.Private
2.Public
3.Protected
4.Internal
(More...)

What is Active Directory? What is the namespace used to access the Microsoft Active Directories? What are ADSI Directories?

  
Active Directory Service Interfaces (ADSI) is a programmatic interface for Microsoft Windows Active Directory. It enables your applications to interact with diverse directories on a network, using a single interface. Visual Studio .NET and the .NET Framework make it easy to add ADSI functionality with the DirectoryEntry and DirectorySearcher components.

Using ADSI, you can create applications that perform common administrative tasks, such as backing up databases, accessing printers, and administering user accounts. (More...)

the difference between a delegate and an event

  
the difference between a delegate and an event

Hi


Here is the difference between a delegate and an event.

Delegate:

public class VikramDel

{

public delegate void VikramExampleDelegate(int num1,string str1);

public VikramExampleDelegate VikramDeleageteCallback;

}

Event:

public class VikramEvent

{

public delegate void VikramExampleEvent(int num1,string str2);

public event VikramExampleEvent VikramEventCallback;

}

So syntax wise there is only one difference that we have to use the event keyword with the event.

So the question comes why do we have a keyword when the same work can be done without using it. But there is a reason for the existence of the keyword event. Lets take an example how would a client work with this class

VikramDel V = new VikramDel();

V.VikramDeleageteCallback +=new

VikramDel.VikramExampleDelegate (this.VikDelegate);

Here we are adding a new target to the invocation list of the delegate. The same code will work with the other class also without any problem

VikramEvent V = new VikramEvent();

V.VikramEventCallback + =new

VikramEvent.VikramExampleEvent(this.VikDelegate);

But consider a case where by instead of adding a new target to the invocation list of the delegate if I simply set a delegate to a new delegate (The difference is with the + sign being not there).

VikramDel V = new VikramDel();

V.VikramDeleageteCallback =new

VikramDel.VikramExampleDelegate (this.VikDelegate);

This code will work fine here but the same will not work with an event.

So what it means is that if we use the event keyword no client class can set it to null. This is very important. Multiple clients can use the same delegate. After multiple client have added a function to listen to the callback of the delegate. But now one of the client sets the delegate to null or uses the = sign to add a new call back. This means that the previous invocation list will not be used any more. Hence all the previous client will not get any of the callback even if they have registered for the call back.

Hence we can say that the even keyword adds a layer of protection on the instance of the delegate. The protection prevents any client to reset the delegate invocation list. They can only add or remove the target from the invocation list. (More...)

What's a Bubbled Event ?

  
When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents (More...)

What is CODE Access security?

  
CAS is part of .NET security model that determines whether or not a piece of code is allowed to run and what resources it can use while running. Example CAS will allow an application to read but not to write and delete a file or a resource from a folder. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend