Friday, September 30, 2011

23 Important .Net Interview Question

How does performance increase by using generic collection ?

What is the sequence in which ASP.NET page life cycle is executed ?
If you are said to improve .NET code performance what will you do ?
How does “Dataset” differ from a “Data Reader”?
How does delegate differ from an event
What is the difference between abstraction and encapsulation ?
If A class inherits from multiple interfaces and the interfaces have same method names. How can we provide different implementation?.
What is Polymorphism? How does VB.NET/C# achieve polymorphism?
Why can't we instantiate an abstract class?
What is difference between out and ref in c#?
What is the difference between app.config, web.config and machine.config ?

What are the different principle of OOPS?
What is the difference between .NET 1.1,2.0,3.0,3.5 and 4.0 ?
What is the difference between class and structures ?
What are Regex / regular expressions ?
What is the difference between Decorator and Adapter pattern?
What is the difference between Object and class adapters?
How did you do unit testing in your project?
Can you explain architecture of your project ?
What is the use of private constructor ?
What coding standards did you followed your projects ?
What are the different types of assemblies?
How does index makes search faster?
Also see another C# & .Net interview questions video on difference types of collection
in .Net as follows-



Please click here to see more Dotnet interview questions and answers

Regards,

Visit Authors blog for more Most asked .NET interview questions

Thursday, September 29, 2011

ASP.NET interview questions: - How to restrict users to upload a specified file extension in ASP.NET?

This is not one of the typical .NET interview questions but on knowledge aspect
you will find this as interesting because while you are working in some of the
IT company or project this situation can occur in front of you so at that time
this might help you in some extent.

So let’s see a small and simple example to understand it in better manner.

In order to see it practically just follow the following steps.

Step1: - create a new project of ASP.NET for that just go to >> File
>> New >> Project >> Web >> select ASP.NET Empty Web
Application.







Step2: - now, just simply add a Web form page in to your application for
that just go to >> Solution Explorer >> Right click on the project
name
>> Add >> New Item >> Select Web Form.



Step3: - Now Add a FileUpload control and Button control from the ToolBox to the WebForm.aspx Page.




The WebForm.aspx page should appear like below diagram.






Step4: - Now simply just add the below code snippet in to WebForm1.aspx.cs file.

protected void Button1_Click(object sender, EventArgs e)
{
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
// The below line of code with take the extension of the selected file by the user.
string extension = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);

// The below line of code is the location where the file will be saved.
string location = Server.MapPath("UploadedFiles")+"\\"+filename;

// The below “if” condition will see the whether the file is .docx
or not and according to that the condition statement will execute.

if (extension == ".docx")
{
try
{
FileUpload1.PostedFile.SaveAs(location);
Label2.Text = "The File has been successfully uploaded";
}
catch (Exception ex)
{
Label2.Text = "Error : " + ex.Message.ToString();
}
}
else
{
Label2.Text = "Please Select a .docx file only";
}
}
else
{
Label2.Text = "Please Enter a File";
}
}

The above code snippet is for the Button control for uploading the selected file to the server and with the extension condition.

Once you have completed all the above steps just run your application to get a resultant result.




The above diagram is the running page that we have created.

Now, let’s first select a different extension file and see that the file is successfully added to the server or not.





Once you have selected the file now just click on the upload button.





As we have not selected the specified file extension, we expect that the file
should not be saved and an error of block statement should get executed like
below diagram.




The above diagram proves the point that the user can only select the specified
file extension.

Now, let us select a .docx file as we have specified in the code of statement
and see that it is getting saved to the server or not.




Now, just click the upload button to upload the selected file to the server and if everything goes right you will see the result like below diagram.


See the following video on Authentication and Authorization: -





Get more learning materials for ASP.NET interview questions

Regards,

View author’s other article on ASP.NET interview questions

Wednesday, September 28, 2011

ASP.NET interview questions: - How to Browse and Upload a file in ASP.NET?

This not one of those most asked ASP.NET questions , but yes sometimes
interviewer starts getting in to practical things to understand how good you
are as a developer.

So let’s see a small and simple example to understand it in better manner.

In order to see it practically just follow the following steps.

Step1: - create a new project of ASP.NET for that just go to >>
File
>> New >> Project >> Web >> select ASP.NET
Empty Web Application.








Step2: - now, just simply add a Web form page in to your application
for that just go to >> Solution Explorer >> Right click on the
project name
>> Add >> New Item >> Select Web Form.




Step3: - Now Add a FileUpload control and Button control from the ToolBox to the WebForm.aspx Page.



The WebForm.aspx page should appear like below diagram.





Step4: - Now simply just add the below code snippet in to WebForm1.aspx.cs file.

protected void Button1_Click(object sender, EventArgs e)
{
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string location = Server.MapPath("")+"\\"+filename;
try
{
FileUpload1.PostedFile.SaveAs(location);
Label2.Text="The File has been successfully uploaded";
}
catch (Exception ex)
{
Label2.Text = "Error : " + ex.Message.ToString();
}
}
else
{
Label2.Text = "Please Enter a File";
}
}

The above code snippet is for the Button control for uploading the selected file to the server.

Once you have completed all the above steps just run your application to get a resultant result.




The above diagram is the running page we have created, now just click on the browse button to select a file from desired location.


Once you have selected the file now just click on the upload button.




Now if everything goes right you will see a result like below diagram.



View the following video on use of Static keyword: -





Get more learning materials for ASP.NET interview questions

Regards,

View author’s other article on ASP.NET interview questions

Tuesday, September 27, 2011

.NET interview questions: - What are the difference between ForeGround and BackGround Threading?

Threading: - threading is a parallel processing unit and helps you to
access multiple tasks at a one moment of time.

A managed thread is either the Foreground thread or a Background thread.
Background threads are identical to foreground threads with one exception: a
background thread will not keep the managed execution environment alive. Once
all foreground threads have been stopped in a managed process, the system stops
all background threads and shuts down.

The following points will show the difference between the Foreground and
Background thread.

1. Foreground threads have the ability to prevent the current application
from terminating. The CLR will not shut down an application until all
Foreground
threads have ended.

2. Background threads are viewed by the CLR as expendable paths of
execution that can be ignored at any point in time. Thus, if all Foreground
threads have terminated then all Background threads are automatically
killed when the application domain unloads.

Now, let’s create a simple demonstration to see the exact difference between the
Foreground and Background thread.

In order to see it practically just follow the following steps.

Step1: - Create a new project of Console Application for that just go to
>> File >> New >> Project >> Windows >> Select
Console Application.







Step2: - Import the namespace using System.Threading; in your
program.cs file.



Step3: - Now just add the below code snippet in your program.cs file.

using System.Threading;

namespace ConsoleApplication1
{
class Program
{
static void Main()
{
Test objLongTest = new Test(20);// Passing the value as 20.
//just called the Function1 in the foreground thread.
Thread fgThread = new Thread(new ThreadStart(objLongTest.Function1));
fgThread.Name = "Foreground Thread";//assigned the Name to the thread.
Test objShortTest = new Test(10);// Passing the value as 10.
//just called the Function1 in the background thread.
Thread bgThread = new Thread(new ThreadStart(objShortTest.Function1));
bgThread.Name = "Background Thread";//assigned the Name to the thread.
bgThread.IsBackground = true;//set the IsBackground property as true.
fgThread.Start();//Started the Foreground thread.
bgThread.Start();//Started the background thread.
}
class Test
{
int Iteration;
public Test(int Iteration)
{
this.Iteration = Iteration;
}
public void Function1()//created a function.
{
String threadName = Thread.CurrentThread.Name;
for (int i = 0; i < Iteration; i++)
{
Console.WriteLine("{0} count: {1}",
threadName, i.ToString());
Thread.Sleep(350);
}
//the below line will print the thread name to the output screen.
Console.WriteLine("{0} finished counting.", threadName);
Console.ReadLine();
}
}

}
}

Step4: - Now, just run your Console Application and will see result like below diagram.





The above diagram proves that the Foreground thread has the ability to
prevent the current application from terminating.

Watch the following video on thread, background thread and foreground thread in
.NET: -




See our other interview questions and answers for .NET for preparation


Regards,

View author’s other Most asked Dotnet interview question

Monday, September 26, 2011

.NET interview questions: - How to add a code snippet in Visual Studio 2010?

Visual Studio has two types of snippets namely Expansion snippet which are inserted at the cursor and SurroundsWith snippet which wraps around existing code.
Let’s see a small and simple example to understand it in better manner.

In order to see it practically just follow the following steps.

Step1: - create a new project of Console Application for that just go to >> File >> New >> Project >> Windows >> Select Console Application.




Step2: - Add XML file in your project for that just go to >> Solution
Explorer
>> Right Click on the project name >> Add >> Add
New Item
>> Select XML File.


Note: - Please save the XML File with .snippet extension like below diagram.




Step3: - Now just right click on code editor window and select the menu item Insert snippet or Press Ctrl + K + X and click the item Snippet like below diagrams.





As soon as you select Snippet the following tags will be automatically to the code editor window like below diagram.




Step4: - Just remove the tag below as we are creating an Expansion snippet.

<SnippetType>SurroundsWith</SnippetType>
Now simply just make the necessary changes to the tags as I have done in below code snippet.
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>CodeSnippetExample</Title>
<Author>Feroz Shaikh</Author>
<Shortcut>CodeSnippet</Shortcut>
<Description>Add a Header to Code File</Description>
<SnippetTypes>
<!--<SnippetType>SurroundsWith</SnippetType>-->
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Author</ID>
<Default>Feroz Shaikh</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
/**************** Code File Header ******************
Author: $Author$
Date: 26/09/2011
Version: 1.0.0.1
Description: Adding a header to the Code File
****************************************************/
]]>
</Code>
</Snippet>
</CodeSnippet>

Step5: - Now we have to load the snippet in the Visual Studio for that we have to use Code Snippet Manager which comes under Tools menu like below diagrams.

Go to >> Tools >> Customize >> Commands >> Tools >>
Add Command >>Select Code Snippet Manager.








Step6: - Now simply just save the file (MyCodeSnippet.snippet) to your desired location like below diagram.





Step7: - Now just simply open the code snippet manager and click on Import like below diagram.










Step8: - Now just simply open the program.cs file of console application and just add the created snippet in the code like below diagram.

Just right click on the code to add the snippet.







Now you will see that snippet is now being added to the code like below diagram.



Similarly, you can test for the second method SurroundsWith.
Also view our video on CAS, evidence, permission set & code groups as follows: -





Avail from the link more interview questions and answers for .NET for preparation.

Regards,

Refer author’s other blog for complete Most asked .NET interview questions

Saturday, September 24, 2011

12 Videos on important .NET interview Questions & Answers

In this video series we will see videos on some 12 important .NET and c# interview questions like Generics,garbage collector,CAS,Private constructors,Anonymous methods, Diff betwn Unique and primary key/convert and tostring,checked and unchecked ..Lot more

for more .net and c# interview questions videos click on .NET and c# interview questions

C# interview questions :- How do you debug C# applications using Visual studio ?.

I use the following things for debugging c# applications using visual studio :-

1. Step over if we want to move one step after other.

2. Step in , if we want to move in to a function.

3. Step out , if we want to move out of the function.

4. Add watch and Quick watch to see the variable data.

5. Intellitrace to back trace debugging history.

Put the below link of the video




Get more materials on c# interview questions and answers

Regards,

Also see author’s other blog on Most asked c# interview questions

5 tips to debug c# program using visual studio 2010 ( f10,11 watch windo...


for more .net and c# interview questions videos click on .NET and c# interview questions

Friday, September 23, 2011

SQL Server interview questions: - State the term SQL injection in SQL Server?

This is one of the most favorite SQL Server interview questions asked by the
interviewer.

It is basically a Form of attack on a database-driven Web site in which the
attacker executes unauthorized SQL commands by taking advantage of insecure code
on a system connected to the Internet, bypassing the firewall. SQL injection
attacks are used to steal information from a database from which the data would
normally not be available and/or to gain access to an organization’s host
computers through the computer that is hosting the database.

SQL injection attacks typically are easy to avoid by ensuring that a system has
strong input validation.

As name suggest we inject SQL which can be relatively dangerous for the
database. Example this is a simple SQL

SELECT email, passwd, login_id, full_name
FROM members
WHERE email = 'x'

Now somebody does not put “x” as the input but puts “x ; DROP TABLE members;”. So the actual SQL which will execute is:-

SELECT email, passwd, login_id, full_name
FROM members
WHERE email = ‘x’; DROP TABLE members;

Think what will happen to your database.

Also see another SQL server interview questions video on difference between unique key and
primary key as follows: -



Get more materials on Sql Server interview questions
Regards,

Also see author’s other blog on SQL server interview questions



Thursday, September 22, 2011

.NET interview questions: - What are the difference between .NET Framework 4 and .NET Framework 4 Client Profile?

.NET Framework 4 Client Profile: - The .NET Framework 4 Client Profile is a downsized version of .NET Framework 4 and is basically used when you want to create windows based applications and you do not want the complete framework to be installed.
Now, let’s see the features that are not included in the .NET Framework 4 Client Profile.

As it’s a downsized version following are not included in the .NET Framework 4
Client Profile as compared to the .NET Framework 4.


1. ASP.NET.

2. Advanced Windows Communication Foundation (WCF) Functionality.

3. .NET Framework Data Provider for Oracle.

4. MSBuild for Compiling.

Now, let’s see a small demonstration to understand it better manner and also
prove the above points.

Step1: - create a new windows application for that just GoTo > File >
New > Project > Windows > Select Windows Form Application
like below
diagrams.








Note: - In the above diagram you can see that I have target the framework
as .NET Framework 4.

Now, let’s see that which framework is been assigned to your Windows Application
by the visual studio for that just Right click on the Project Name > Go To >
Properties
. As soon as you click on properties a new window will open like
below diagram.





In the above diagram you can clearly see that the Visual Studio selected the Framework as .NET Framework 4 Client Profile by default.

Now, let’s see what happens when we create a project on ASP.NET.

Create a new project of ASP.NET application for that just go to > File > New
> Project > Web > Select ASP.NET Web Application
like below diagrams.







Note: - In the above diagram you can see that I have target the framework as .NET Framework 4.

Similarly, let’s see that which framework is been assigned to your Windows
Application by the visual studio for that just Right click on the Project
Name > Go To > Properties
. As soon as you click on properties a new window
will open like below diagram.


Now, in the above diagram you can clearly see that the Visual Studio has selected the framework as .NET Framework 4.

The above difference proves that the .NET Framework 4 Client Profile does not
include feature of ASP.NET.

Similarly, you can demonstrate simple to see the further differences between the
.NET Framework 4 and .NET Framework 4 Client Profile.

Watch video on regular expression with practical demonstration as follows: -





Get more materials on interview questions and answers for .NET

Regards,

See more stuffs on author’s blog for Most asked Dotnet interview question