You are on page 1of 13

1. What are OOP Concepts?

Data Abstraction
Inheritance
Data Encapsulation
Polymorphism

2. What is the difference between arrays and collection?

Array:

1. You need to specify the size of an array at the time of its declaration. It cannot
be resized dynamically.
2. The members of an array should be of the same data type.

Collection:

1. The size of a collection can be adjusted dynamically, as per the user's


requirement. It does not have fixed size.
2. Collection can have elements of different types.

4. Explain about sealed class?

You can prevent a class from being inherited further by defining it with
the sealed keyword.

5. How is method overriding different from method overloading?

Overriding involves the creation of two or more methods with the same name and
same signature in different classes (one of them should be parent class and other
should be child). 

Overloading is a concept of using a method at different places with same name and
different signatures within the same class.

6. What is the difference between a class and a structure?

Class:

1. A class is a reference type.


2. While instantiating a class, CLR allocates memory for its instance in heap.
3. Classes support inheritance.
4. Variables of a class can be assigned as null.
5. Class can contain constructor/destructor.

Structure:
1. A structure is a value type.
2. In structure, memory is allocated on stack.
3. Structures do not support inheritance.
4. Structure members cannot have null values.
5. Structure does not require constructor/destructor and members can be
initialiazed automatically.

7.  Define enumeration?

Enumeration is defined as a value type that consists of a set of named values. These
values are constants and are called enumerators. 

enum Fruits {Mango, Apple, orange, Guava}; 

8. Can you inherit private members of a class?

No, you cannot inherit private members of a class because private members are


accessible only to that class and not outside that class.

9. What is a namespace?

Namespace is considered as a container that contains functionally related group of


classes and other types.

10. Do events have return type?

No, events do not have return type.

11. Can users define their own exceptions in code?

Yes, customized exceptions can be defined in code by deriving from


the System.Exception class.

12. Is it possible to execute two catch blocks?

You are allowed to include more than one catch block in your program; however, it is
not possible to execute them in one go. Whenever, an exception occurs in your
program, the correct catch block is executed and the control goes to the finally block
if exists.

13. Which are Access Modifiers available in C# ?

All types and type members have an accessibility level, which controls whether they
can be used from other code in your assembly or other assemblies. You can use the
following access modifiers to specify the accessibility of a type or member when you
declare it:

public: The type or member can be accessed by any other code in the same assembly
or another assembly that references it.

private: The type or member can be accessed only by code in the same class or struct.

protected: The type or member can be accessed only by code in the same class or
struct, or in a class that is derived from that class.

internal: The type or member can be accessed by any code in the same assembly, but
not from another assembly.

14.  Data Types in C#?

bool, byte , char, decimal , double, float, int, long, sbyte , short, uint, ulong, ushort.

15. Explain operator precedence in c#?

Operator precedence determines the grouping of terms in an expression. This affects


evaluation of an expression. Certain operators have higher precedence than others;
for example, the multiplication operator has higher precedence than the addition
operator.

For example x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has


higher precedence than +, so the first evaluation takes place for 3*2 and then 7 is
added into it.

16. What are the advantages of OOP?

Following are the advantages of OOP:

It presents a simple, clear and easy to maintain structure.

It enhances program modularity since each object exists independently.

New features can be easily added without disturbing the existing one.

Objects can be reused in other program.


17. What is Abstract method?

Abstract method doesn't provide the implementation & forces the derived class to
override the method.

18. What is "this" pointer?


This pointer is a pointer which points to the current object of a class. this is actually a
keyword which is used as a pointer which differentiate the current object with global
object.

19. Can we have Multiple Main Methods in one .cs file?

Yes we can Have multiple Main methods in one .cs file.

The crux is we can have Multiple classes in one .cs file; and we can define one Main
method in each class.& while doing compliation we can spcify the compiler to choose
the Main methods from the specific class .

20. What is the default access modifier of a class?

The default access modifier for a class is internal if it's defined within the same
namespace. It is private if it's defined within another class.It can declare members
(methods etc) with following access modifiers:

Public

Internal

Private

protected internal

-------------------------------------------------------------------------------------------------------

State Management

-------------------------------------------------------------------------------------------------------

21. What is state management?

State management is the process by which you maintain state and page information
over multiple requests for the same or different pages. 

22. Http is stateless, What does this mean?

Stateless protocol is a communications protocol that treats each request as an


independent transaction that is unrelated to any previous request so that the
communication consists of independent pairs of requests and responses.

23. What is Session?

We know that Http is stateless, means when we open a webpage and fill some
information and then move to next page then the data which we have entered will
lost.
It happed do to Http protocol stateless nature. So here session come into existence,
Session provide us the way of storing data in server memory. So you can store your
page data into server memory and retrieve it back during page postbacks.

24. What are the Advantage and disadvantage of Session?

Advantages:
Session provide us the way of maintain user state/data.

It is very easy to implement.One big advantage of session is that we can store any
kind of object in it. :eg, datatabe, dataset.. Etc By using session we don't need to
worry about data collesp, because it store every client data separately. Session is
secure and transparent from the user. Disadvantages: Performance overhead in case
of large volumes of data/user, because session data is stored in server memory.
Overhead involved in serializing and de-serializing session data, because in the case
of StateServer and SQLServer session modes, we need to serialize the objects before
storing them.

25. What is Session ID in Asp.net?

Asp.Net use 120 bit identifier to track each session. This is secure enough and can't
be reverse engineered. When client communicate with server, only session id is
transmitted, between them. When client request for data, ASP.NET looks on to
session ID and retrieves corresponding data.

26. What are Session Events?

There are two types of session events available in ASP.NET: Session_Start


Session_End You can handle both these events in the global.asax file of your web
application. When a new session initiates, the session_start event is raised, and the
Session_End event raised when a session is abandoned or expires.

27. How you can disable session?

If we set session Mode="off" in web.config, session will be disabled in the


application.

<configuration>
  <sessionstate  Mode="off"/>
</configuration>

28. What is difference between Hyperlink Vs LinkButton in ASP.NET?

A Hyperlink just redirects to a given URL identified by "NavigateURL" property.


However a LinkButton which actually displays a Hyperlink style button causes a
postback to the same page but it doesn't redirect to a given URL.

29. explain briefly about ASP.NET Page life Cycle?


ASP.NET page passes through a series of steps during its life cycle. Following is the
high-level explanation of life cycle stages/steps.

Initialization

LoadViewState

LoadPostBackData

Load

RaisePostBackEvent

SaveViewState

Render

Dispose

30. Difference between Response.Redirect and Server.Transfer?

In case of Response.Redirect, a new request is generated from client-side for


redirected page. It’s a kind of additional round trip. As new request is generated from
client, so the new URL is visible to user in browser after redirection.
While in case of Server.Transfer, a request is transferred from one page to another
without making a round trip from client. For the end user, URL remains the same in
browser even after transferring to another page.

31. Types of State Management

There are mainly two types of state management that ASP.NET provides:

Client side state management


Server side state management

Client side state management techniques

View State
Control State
Hidden fields
Cookies
Query Strings

Server side state management techniques

Application State
Session State
32. Explain about View State in ASP.Net ?

ASP.NET uses this mechanism to track the values of the controls on the web page
between page request for same page. We can also add custom values to view state.
ASP.NET framework takes care of storing the information of controls in view state
and retrieving it back from viewstate before rendering on postback.

33. How to manage state by using cookies in ASP.Net?

There are scenarios when we need to store the data between page requests. So far, the
techniques we have discussed store the data for the single page requests. Now we
look at the techniques that store information between page requests.

34. Write syntax for get and set cookies,session,viewstate,querystring in ASP.Net?

35. Explain about QueryString in ASP.Net?

Query strings are commonly used to store variables that identify specific pages, such
as search terms or page numbers. A query string is information that is appended to
the end of a page URL. They can be used to store/pass information from one page to
another to even the same page.

//GetDataItem from querystring


if (Request.QueryString["number"] != null)
{
Label4.Text = Request.QueryString["number"];
}
//set in query stringint postbacks = 0;
if (Request.QueryString["number"] != null)
{
postbacks = Convert.ToInt32(Request.QueryString["number"]) + 1;
}
else
{
postbacks = 1;
}
Response.Redirect("default.aspx?number=" + postbacks);
36. What is Application state and session state in ASP.Net?

a) Use Session state variables to store items that you want keep local to the
current session (single user).

b) Use Application state variables to store items that you want be available to
all users of the application.

37. What are the advantages of using Query Strings?


Query strings are easy to implement.
Browser support for passing values in a query string is nearly universal.
Query strings are contained in the HTTP request for a specific URL and do not
require server resources.

38. What is Cookie Dictionary? 

A cookie dictionary is a single cookie object that stores multiple pieces of


information. You use the Values property to access and assign new values to the
cookie dictionary.

39. How do you create a Cookie that never expires?

To create a Cookie that never expires set the Expires property of the Cookie object to
DateTime.MaxValue.

40. Are Cookies secure?

No, Cookies are not secure. You must pay attention to the type of data you store in
cookies.

a) Cookies are not designed to store critical information so storing passwords in


a cookie is a bad idea.

b) Keep the lifetime of a cookie as short as practically possible.


Encrypt cookie data to help protect the values stored in the cookie.

-------------------------------------------------------------------------------------------------------

Validations

-------------------------------------------------------------------------------------------------------

41. What are the 6 different validation controls provided by ASP.NET? 


RequiredFieldValidator:Checks whether a control contains data
CompareValidator:Checks whether an entered item matches an entry in another
control RangeValidator:Checks whether an entered item is between two values
RegularExpressionValidator:Checks whether an entered item matches a
specified format
CustomValidator:Checks the validity of an entered item using a client-side
script or a server-side code, or both

ValidationSummary:Displays validation errors in a central location or display a


general validation error description
42. What property of the validation control is used to specify which control to
validate?
ControlToValidate property.

43. Are the validation controls fired on the client side if javascript is disabled on
the client browser?

No, validation controls are not fired on the client side if javascript is disabled on
the client browser.

44. What is the use of CausesValidation property of an ASP.NET button


control? 

CausesValidation property of an ASP.NET button control is used to determine if the


validation controls should be fired when the button is clicked. If CausesValidation
property is set to true, then validation is performed and if the CausesValidation
property is set to false then validation is not done.

45. How do you programatically check, if the client side validation is not
bypassed by disabling the javascript on the client browser?

We use Page.IsValid property to determine if all the validations have succeeded. For
this property to return true, all validation server controls in the current validation
group must validate successfully.

46. What is a validation group?

Validation groups allow you to group validation controls on a page as a set. Each
validation group can perform validation independently from other validation groups
on the page.

47. How do you create a validation group?

You create a validation group by setting the ValidationGroup property to the same
name for all the controls you want to group. You can assign any name to a validation
group, but you must use the same name for all members of the group.

48. Can a DropDownList fire validation controls?

Yes, DropDownList control can also fire validation if the control's CausesValidation
property is set to true and the AutoPostBack property is set to true.

49. What is InitialValue property of a RequiredFieldValidator?

Use this property to specify the initial value of the input control.Validation fails only
if the value of the associated input control matches this InitialValue upon losing
focus.
50. What are the different validation controls available in ASP.Net?

RequiredFieldValidator: Verifies whether a control contains data

CompareValidator: Verifies whether an entered item matches an entry in another


control

RangeValidator: Verifies whether an entered item is between two values

RegularExpressionValidator: Verifies whether an entered item matches a specified


format

CustomValidator: Verifies the validity of an entered item using a client-side script


or a server-side code, or both

ValidationSummary: Displays validation errors in a central location or display a


general validation error description.

51. What is the use of Display property in validation controls in asp.Net?

Display - Determines how the error messages will be displayed. Possible values are
"None" (error message will not be displayed), "Static" (space for the error message is
allocated in the page layout), "Dynamic" (space for the validation message is
dynamically added to the page).
52. What is the syntax for range validator control when max and min values are
given?
<asp:rangevalidator id="RangeValidator1" runat="server" style="top: 194px; left:
365px;position: absolute; height: 22px; width:105px" errormessage="RangeValidator"
controltovalidate="TextBox4" maximumvalue="100" minimumvalue="18"
type="Integer"></asp:rangevalidator>

53. Is compare validator compare Date,give syntax to compare date?


Yes, compare validator can compare Date. Syntax is given below
<asp:CompareValidator ID="cmpVal1" ControlToCompare="txtStartDate"
ControlToValidate="txtEndDate" Type="Date" Operator="GreaterThanEqual"
ErrorMessage="*Invalid Data" runat="server"></asp:CompareValidator>

-------------------------------------------------------------------------------------------------------

Controls Properties and Events

-------------------------------------------------------------------------------------------------------

54. What’s the difference between Server controls and HTML controls?

1. Server controls can trigger control-specific events on the server.HTML


controls can trigger only page- level events on server (postback).
2. Data entered in a server control is maintained across requests. Server controls
retain state.Data is not maintained in an HTML control. Data must be saved and
restored using page-level scripts.
3. The Microsoft .NET Framework provides a set of properties for each server
control. Properties allow you to change the server control’s appearance and
behavior within server-side code.HTML controls have HTML attributes only.
4. Server controls automatically detect browser and adapt display as
appropriate.HTML controls do not adapt automatically. You must detect browser
in code or write for least common denominator..

55. What are the 2 types of controls that you can use on a webform in
ASP.NET?
Web Server Controls
HTML Controls

56. How can you prevent users from editing Text in TextBox control on a web
form?
By making the TextBox a readonly TextBox. To make a TextBox readonly set
the ReadOnly property to True.

57. How do you convert an ASP.NET TextBox to accept passwords? 


To convert and ASP.NET TextBox to accept passwords set the TextMode
property to "Password"

58. What happens when you set the AutoPostBack property of a TextBox to
true?
When AutoPostBack property is set to True, the TextBox control fires a
TextChanged postback event when the user leaves the TextBox control after
changing the contents. By default, this property is set to False and the Text 颅
Changed event is cached until some other postback event occurs.

59. What are the 3 values that a TextMode property of TextBox can have? 
SingleLine : Single Line TextBox
MultiLine : Multi Line TextBox(scrollable)
Password : When set to Password, the text box displays dots in place of the
characters typed.

60. How do you limit the number of characters entered by a user in the
ASP.NET TextBox?
By setting the MaxLength property of the TextBox. If you set the MaxLength
property to 10, a user can enter only 10 characters into the TextBox..

61. What is the use of rows and columns properties in asp TextBox in asp.net

Columns: The width of the text box in characters. The actual width is determined
based on the font that is used for the text entry.
Rows:The height of a multi-line text box in lines. The default value is 0, means a
single line text box.
62. What is the use of GroupName property for a radio Button in asp.net?
GroupName:Name of the group the control belongs to.
63. What are the list controls provided by asp.net explain each?
 Drop-down list,
 List box,
 Radio button list,
 Check box list,
 Bulleted list.

64. What is the name event client side when button click in asp.net?

OnClientClick=”dhbd();”

65. List total events of GridView control in asp.net ?

PageIndexChanged Event
PageIndexChanging Event
RowCancelingEdit Event
RowCommand Event
RowCreated Event
RowDataBound Event
RowDeleted Event
RowDeleting Event
RowEditing Event
RowUpdated Event
RowUpdating Event
SelectedIndexChanged Event
SelectedIndexChanging Event
Sorted Event
Sorting Event

66. List total events of Repeater control in asp.net ?

CallingDataMethods Event
CreatingModelDataSource Event
ItemCommand Event
ItemCreated Event
ItemDataBound Event

67. How to use RowDataBound Event of GridView control in asp.net explain?


68. How to fire a button click event from JavaScript in ASP.NET?
var clickButton = document.getElementById("<%= btnClearSession.ClientID %>");
clickButton.click();

69. List total events of RadioButtonList control in asp.net ?

DataBinding DataBound SelectedIndexChanged


70. How to use DataList in asp.Net and List all Events of this?
CancelCommand Event
DeleteCommand Event
EditCommand Event
ItemCommand Event
ItemCreated Event
ItemDataBound Event
UpdateCommand Event

You might also like