Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

ASP.net, C# Interview Questions - 1

Uploaded by

Pavan Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

ASP.net, C# Interview Questions - 1

Uploaded by

Pavan Reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Asp.

Net interview questions

 Below are the Recent interview questions for Asp.Net developers: (as on 07/2011)

1Q. What method to use for storing viewstate into d/b?

A: Implement the “abstract class PageStatePersister” class, with our custom class to serialize data into
binary format. Or override LoadViewstate(), SaveViewState() methods of “Control” class from our
custom server control.

Check: http://msdn.microsoft.com/en-us/library/system.web.ui.pagestatepersister.aspx

2Q. Extensible Output Caching – a feature in asp.net?

A: Yes. extend output caching and to configure one or more custom output-cache providers. storage
options can include local or remote disks, cloud storage, and distributed cache engines. Check:
http://msdn.microsoft.com/en-us/library/ms228124.aspx and
http://www.4guysfromrolla.com/articles/061610-1.aspx

3Q. How to get notified if thread from threadpool completed executing method?

A: In order to be notified when a method is complete, you must supply a callback delegate on the
BeginInvoke(). Delegate type -> new AsyncCallback(CallBack), // callback delegate. check:
http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx

4Q. Write code for reverseChars(whole string), reverseWords & Sort collection (in C#).

A: Static void Main()


{
Console.WriteLine(ReverseString("framework 1234"));
Console.WriteLine(reverseword("framework 1234"));
Console.WriteLine(sortwords("framework 1234 ddd aaa"));
}

// reverses whole string by char level


public static string ReverseString(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}

//reverses string by word level


public static string reverseword(string s)
{
string[] substr = s.Split(" ".ToCharArray());
Array.Reverse(substr);
return String.Join(" ",substr);
}

// sorts collection
public static string sortwords(string s)
{
List<string> lst = new List<string>();
lst.Add("zz"); lst.Add("ff"); lst.Add("ww"); lst.Add("aa");
lst.Sort();
return String.Join(" ",lst.ToArray());
}

5Q. write logic for custom paging implementation in asp.net?

http://rajudasa.blogspot.com
Asp.Net interview questions

A: implemented with SqlProcedure and ObjectDataSource control or custom-component (BAL).


(check sql code and logic from other sources).

6Q. What is CAS?

A: Code Access Security! Revolves around groups(zones) and permissions. It’s a security model which
determines code is allowed to run or allowed to access a resource etc permissions. Mainly components
from internet, intranet etc zones are checked.

7Q. can we customize serialization?

A: Yes, we can using the attributes (ex:[nonserializable]) or mainly with Iserializable interface
implementation with our class (object).

8Q. UDF can be accessed/called for c# coding?

A: Yes, like any other aggregate function, we can call it from sql query. Ex: sql = “Select
mydb.dbo.udFunction(val) As result”. But not like directly stored-procedure call.

9Q. How to apply Master page dynamically?

A: from content page (.aspx) under “onPreInit” event-handler write this code:

Page.MasterPageFile = “MainMaster.master”;

10Q. What happens if implement Interface first then inherit Class next from your class?
Ex: class Child : I1, BaseA
A: It’s not allowed, since specification (from ECMA standard) says so. And its convention followed by
compilers, that class comes first then interfaces next. Ex: class Child : BaseA, I1,I2

11Q. check this code, is it allowed?

I1 -> show(); & I2 -> show(); // both interfaces contain same method

class Child : I1,I2

and how to call I1.show()?

A: Yes, Its allowed. I1.show() requires explicit implementation in class Child without access-modifier.
Ex: void I1.show(){ .. }

I1 obj = new Child();

I1.show();

12Q. Can you point out Structure types in .Net FCL?

A: Types: Size, Point from System.Drawing namespace are structure types and also Nullable<T> is
too.

13Q. How to call Button1 click event from Button2 click event handler? (Win Form)

A: In windows Appl. Write under Button2 click event handler: Button1.PerfromClick();

http://rajudasa.blogspot.com
Asp.Net interview questions

14Q. When and where to use Abstract classes and Interfaces?

A: use Abstract classes if you are creating 3rd party component (public & sharable).
Or use Interface for private projects.

15Q.How to allow exactly 3 password attempt to login for user?

A: place the username in application object or D/B then count and check the password attempts.
Forms Authentication – Membership provider by default provides this functionality.

*16Q. check this code:

Class A{ public virtual int show(){ return 1; } }

Class B : A{ public new int show(){ return 2; } }

B obj = new A(); int x = obj.show();

Now tell me what value ‘x’ variable is holding?

A: Error: cannot implicitly convert A to B.

17Q. Assign DataSet to a TextBox, fill it with single value, using one line of coding?

A: ds.Tables[0].Rows[0]["ColumnName"].ToString();

or declaratively:

<asp:TextBox id="txtName" Runat="server" Text='<%# DataBinder.Eval(demoData1,

"Tables[Table1].DefaultView.[0].Name") %>'/>

18Q. Generally asked Gridview events?

A: Gridview events:

DataBinding Occurs when the server control binds to a data source. (Inherited from Control.)

DataBound Occurs after the server control binds to a data source. (Inherited from
BaseDataBoundControl.)

RowCommand Occurs when a button is clicked in a GridView control.

RowCreated Occurs when a row is created in a GridView control.

RowDataBound Occurs when a data row is bound to data in a GridView control.

(and other common events for sorting, paging, editing, updating, deleting, selecting operations can be
found, check here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview_events.aspx )

19Q. What is the use of Sql Parameters in coding?

http://rajudasa.blogspot.com
Asp.Net interview questions

Advantages of sql parameters:

 They can prevent the sql injection attacks. by preserving any sql string formats(but not concat
to coding).
 Easy to understand the sqlquery while dynamic sql creation.

20Q. Mention some Abstract classes used in .Net FCL?

A: CollectionBase, DictionaryBase, DbConnection, DbCommand etc.

21Q. Write a query to add two columns from a table and show a single column result?

A: select (col1+col2) as sum from table1

22Q. Inner Join or Outer Join requires Foreign-Key between tables to use them?

A: No, not required. (Note: ‘ON’ condition is mandatory)

23Q. Is there any “sum()” aggregate function in sql server?

A: Yes, sum(columnName) used to add the single column values, giving a total value.

24Q. what’s the Inner Join and Left Outer Join output of below tables?

tableA & tableB

Col1
col1
1
Null
5
1
Null
6

A: Inner Join & Left Outer Join

1 1 1 1
Nul Nul
l l
6 Nul
l

25Q. To Add or Update a property to TextBox, what type you use: UserControl or Custom Server
Control?

A: Custom Server Control is used to Alter or creating a control from scratch. It’s a class library project
(DLL).

http://rajudasa.blogspot.com
Asp.Net interview questions

26Q. Difference between Master Pages and User controls?

A: Master pages provide common layout. User control used to aggregate controls, both are useful for
reuse and better maintenance.

27Q. How many Clustered & Non-Clustered indexes can be created in a table?

A: 1 Clustered (by default PK column) & 249 for 2005v, 999 for 2008v, Non-Clustered indexes can be
created.

28Q. ADO.NET: ExecuteNonQuery() method returns? If yes what?

A: Yes it returns int type, number of rows affected.

29Q.How to validate textbox value is numeric in javascript?

A:
function isInteger(s){
var i; s = s.toString();
for (i = 0; i < s.length; i++) {
var c = s.charAt(i);
if (isNaN(c)) {
alert("Given value is not a number");
return false;
}
}
return true;
}
<input type=text name=en onKeyup="isInteger(this.value)">
30Q. In which event all web controls are initiated/initialized in asp.net?

A: Init - event raised after all controls have been initialized.

31Q. How to get gridview or dataset from one page to another page?

A: use the PostbackUrl on Button or Server.Transfer() from code in first page with public property
providing access to that gridview or dataset. From the second page, use the “Page.PreviousPage” to
get the first page and access its public property. (check my blog post for details and code).

32Q. How to filter gridview data based on dropdownlist selected item and by declaratively (not
programmatically) ?

A: Enable the ‘AutoPostback’ on dropdownlist, use the SqlDataSource control with ‘ControlParameter’
point to this dropdownlist and then assign this datasource control to gridview.

33Q. ‘OnInit()’ is a virtual method in Page class?

A: Yes, it’s a virtual method, also there is an ‘Init’ event which is not.

34Q. Is ‘commit work’ exists? What is the difference with commit transaction?

A: Yes ‘commit work’ existing, both are same.

http://rajudasa.blogspot.com
Asp.Net interview questions

35Q. Is ‘@transaction’ directive exists in asp3.0?

A: Yes, <% @transaction=value language=”” %>

36Q. What method constructs Page control tree?

A: FrameworkInitialize() method.

37Q. If Page contains <file upload> control, the <form> should contain the ___ attribute?

A: ENCTYPE=”multipart/form-data”

38Q. How to get client/browser preferred language by coding?

A: use, Request.UserLanguages (or) ServerVariable[“http_accept_language”]

39Q. How to retrieve page control value from UserControl?

A: Provide public property in Page, from Usercontrol, use “this.Page”, cast it to specific page type, then
call its public property.

40Q. How to call Page method when Button in User control is clicked?

A: Call public method in Page class from usercontrol of click event after casting the Page to specific
type, or implement the event delegate in usercontrol and allow the container pages to subscribe, so
that user control can call this delegate under button click.

41Q. Difference between ‘Table Variable’ and ‘Temp Table’ in sql server?

A: TV: stored in RAM, No Foreign key support. TT: stored in TempDB d/b, supports Foreign key.

42Q. Types of Polymorphism?

A: 1. Compile time (early binding) -> method overloading.

2. Runtime (late binding) -> method overriding.

43Q. Sealed Class vs Private constructor class?

A: Both classes are not derivable. Instances can be created for Sealed class, virtual methods can’t be
created in sealed class. Instances can’t be created for Private constructor class, provide public static
method which will return this instance. Virtual methods can be created in private constructor class. For
further info, Check singleton pattern.

44Q. Difference between Application Object and Cache Object?

A: Application object: 1.Not threadsafe, use Lock(), UnLock() explicitly. 2. No expiration policy.

Cache Object: 1. Threadsafe (implicit locks). 2. Supports expiration policy (file, time, sql).

45Q. Repeater control supports ‘Sorting’?

A: Repeater control not supports, sorting, editing, paging etc.

http://rajudasa.blogspot.com
Asp.Net interview questions

46Q. Dispose vs GC?

A: for disposing Unmanaged memory, user may call Dispose() method explicitly, which disposes
memory as need is over. Sometime later GC calls the destructor which handles the release of
unmanaged memory.

47Q. Write sql query to get first 100 records?

A: Select top 100 * from table1

48Q. what strongly types master pages?

A: Typecast Page.Master object to specific masterpage type and use it (or) use "@ MasterType
directive" to access the specific masterpage properties/methods is called strongly typed master pages.

49Q. What are the members of IHttpHandler interface (ashx)?

A: "ProcessRequest()" method, "IsReusable" property.

50Q. Diff b/w UNION and UNION ALL in sql server?

A: “union” not allows duplicates, “union all” allows.

51Q. whats the diff b/w raisError() and print in SQLServer ?

A: “print” works only in sqlserver, where as raisError() can send information to client (.net).

52Q. how to catch errors in sqlserver?

A: use @@Error (or) use begin try, begin catch blocks.

53Q. What are ADO.NET data providers?

A: 4 data providers -> SqlClient, OracleClient, Oledb, Odbc

54Q. scenario: custom-class object stored in session and placed in sqlserver. It generates error, (the
culprit, custom class) what might be the reason?

A: Object should be serializable.

55Q. What are 4 parts of strong Name?

A: The name of an assembly consists of four parts: shortName, culture, version, PublickeyToken. Thus,
two strong named assemblies can have the same PE file name and yet .NET will recognize them as
different assemblies. The public key token is used to make the assembly name unique.

Actually, strong name for an assembly consists of five parts: a public key, a simple name, a
version, an optional culture, and an optional processor architecture.

Refer: http://en.wikipedia.org/wiki/.NET_assembly and


http://msdn.microsoft.com/en-us/magazine/cc163583.aspx

56Q. global.asax inherits from what class?

http://rajudasa.blogspot.com
Asp.Net interview questions

A: Global.asax generates a class called "global". global class derives fron the
System.Web.HttpApplication class.

57Q. How to retrieve specific rows(based on condition) from datatable without dataview?

A: DataRow[] dr = ds.Tables[0].Select("<condition>");

58Q. Serialize/save dataset to a file on filesystem, is it possible?

A: yes, with “WriteXml()” method of dataset.

59Q. Difference between “clone” vs “copy”?

A: “Clone” will copy the structure of a data (Deep copy) where as “Copy” will copy the complete
structure as well as data (shallow copy).

60Q. How to create user in windows authentication?

A: using Microsoft® Windows NT… domain controller or Microsoft Windows… Active Directory.

61Q. Default timeout in sqlconnection with sqlserver? and how to extend it?

A: The default value is 15 seconds. Set "Connection Timeout=30" in ConnectionString.

62Q. WCF contract types?

A: 4 types applied on classes as attributes:

ServiceContract, DataContract, FaultContract, MessageContract (and OperationContract applied on


method).

63Q. HTML: @import is used for what purpose?

A: The @import rule allows you to include external style sheets in your document.

Ex: <style type="text/css">


@import url("import1.css");
@import url "import2.css";
</style>

64Q. In javascript, what is the output for these: (a)"6"+"5"*2, (b) 5+true, (c) [1, 2, 3].join(",") ?

A: (a) 610, (b) 6, (c) 1, 2, 3

 Besides the above questions, Below are the frequently asked basic
questions:

http://rajudasa.blogspot.com
Asp.Net interview questions

1. Assembly types -> 3


2. Cache types -> 3
3. Session stores -> 3
4. Authentication types -> 3
5. Validation controls in asp.net -> 5
6. Client-side & server-side State management.
7. What Web.config, Manchine.config files?
8. What is Assembly, manifest, delegate, nested class?
9. Filestream attribute in sql server 2008.
10. Diff. b/w sqlserver05 & sqlserver08.
11. “Render” on controls and on Page is an Event or method?
12. What are Application Events & Session Events?
13. What are singleton, abstract factory patterns?
14. What A,B,C of WCF?

Explain in detail or briefly about them.

 If you have 3+ years of experience, check this slip test:

1Q. What is the best way to integrate 3rd party component into your application?

Application 3rd party


Communication Bridge component

2Q. Write the logic to communicate with different data sources (DBMS) using common classes?

 System Test:

1 Test - Localhost only asp.net applicable:


2fields - source, destination (user enters the folders path-names) and a button in one page.
Validations: shouldn't be empty, shouldn't be same, folders should exist, shouldn't subfolder of
each other.
Tasks: Copy doc, rtf, pdf files from source to destination folder. Create 2 folders for doc and rtf
file types in destination folder (once) and place files in them. If its pdf file, place it in both doc
and rtf folders. Do iterate over subfolders of source folder. At last send the xml file to browser
containing info of total files in each folders of destination folder, like,
Ex: <folders><doc>5</doc><rtf>9</rtf><total>14</total></folders>

2 Test - 3-tier architectured asp.net application:


Using Stored-Procedures, web service, display employee records in one page and record editing,
new record adding in different page. Use validation controls and don’t use dataset or datatable
for data-binding.

http://rajudasa.blogspot.com
Asp.Net interview questions

 For Asp.Net developers, these are the topics from which interview
questions will be asked/expected:

 OOPS concepts (in C#)


 Asp.Net technology
 Javascript & HTML
 ADO.Net
 SQL scripts (sql server).

http://rajudasa.blogspot.com

You might also like