C# and .NET step by step with interview questions
Showing posts with label .Net and c# training. Show all posts
Showing posts with label .Net and c# training. Show all posts
Tuesday, January 15, 2013
Wednesday, December 19, 2012
C# and .NET interview question: -What is short circuiting in C#?

Short circuiting occurs
when you do logical operations like ‘AND’ and ‘OR’.
“When we
use short circuit operators only necessary evaluation is done rather than full
evaluation.”
Let me explain the above sentence with a proper example. Consider a simple “AND” condition code as shown below. Please note we have only one “&” operator in the below code.
Let me explain the above sentence with a proper example. Consider a simple “AND” condition code as shown below. Please note we have only one “&” operator in the below code.
if(Condition1 & Condition2)
{
{
}
In the above case “Condition2” will be evaluated even if “Condition1” is “false”. Now if you think logically it does not make sense to evaluate “Condition 2”, if “Condition 1” is false.It’s a AND condition right? , soif the first condition is false it means the complete ANDcondition is false and it makes no sense to evaluate “Condition2”.
There’s where we can use
short circuit operator “&&”. For the below code “Condition 2” will be
evaluated only when “Condition 1” is true.
if(Condition1 && Condition2)
{
{
}
The same applies for “OR”
operation. For the below code (please note its only single pipe(“|”).) “Condition2” will be evaluated even if
“Condition1” is “true”. If you think logically we do not need to evaluate
“Condition2” if “Condition1” is “true”.
if(Condition1 | Condition2)
{
{
}
So if we change the same to double pipe (“||”) i.e. implement short circuit operators as shown in the below code, “Condition2” will be evaluated only if “Condition1” is “false”.
if(Condition1 || Condition2)
{
{
}
Taken from the best selling interview question book .NETinterview question by Shivprasadkoirala
Here’s an awesome video on concurrent generic collections in C#.
Thursday, October 11, 2012
.NET Interview questions and answers: -What are different access modifiers?
Taken from my book.NET interview questions http://www.flipkart.com/.
There are 5 access modifiers. Access modifiers define scope for members.
There are 5 access modifiers. Access modifiers define scope for members.
·
Private: Accessible only with in the class.
·
Protected: - Accessiblewith in the class and
in derived classes.
·
Friend (internal in C#):- Accessible
anywhere within the current project.
·
Protected friend (protected internal in
C#):- Accessible with current project and derived classes.
· Public: - Accessible everywhere.
One of interesting .NET interview question: -What is the
difference between string and string builder ?
Saturday, September 15, 2012
c# interview question :- What is the difference between Debug and Release?
See the following C# / .NET training video: - In this video we will understand how c# debug and release compile modes are different and when to use them. Debug is mainly meant for development environment while release is meant for production environment.
See for more stuffs on c# interview questions and answers
Regards,
Click to view more from author's on C# training
See for more stuffs on c# interview questions and answers
Regards,
Click to view more from author's on C# training
Monday, June 4, 2012
C# and .NET interview advice for freshers: - Not getting a job for a year should I put fake experience, switch to DBA or pay money for getting a job?
As a .NET interview questions author I always get lots of emails. One of the common things which people ask should I put a fake experience. Below is an answer to one such email.
If someone says pay money to get a job that means they do not need you, you are kind of a baggage on them. Also beware it can be a fraud also. Lately lot of small size software companies and training institutes who are not doing well have turned up to these kind of activities.
When we say we are doing a job, means we are helping company to grow and company pays money in return. So people who are asking for money straight say No No , if that means sitting at home for some time that’s fine, enjoy family.
and other side i am jobless till now and its been 1year,,,and now i don't understand what to do now to see my self as a engineer
If you are jobless for a year you need to see what’s going on wrong. Do connect me personallyfor a mock on .NET interview so that I can personally judge to see what is wrong.
IT market is not so bad. It must be a bit strict for fresher’s but not that horrible as you see. See one is that you are jobless for a year and the other is that in this 1 year you have been to at least 15 interviews and you got till the last round. So if you belong to later part of it that means you are doing well and you should get a job soon.
I personally understand what it means to be at home for a year. But believe me when you get good positions in life ahead you will cherish this struggle and you will be proud of the same.
How about switching to DBA
So one scores high in the number of jobs while the other has less competition. My suggestion would be you have already been trained in NIIT , you are already in full swing of searching a job , stick to .Net for now. You can switch to DBA later when you have a job on hand.
Will a fake 1 year experience help me?
For one Lie you will have to tell 100 Lies ahead. Smaller companies look for people who can code and complete their project. Bigger and mid-level companies look for experience. So start with smaller companies, do not expect sky rocketing salary, be truthful, show your expertise by showing some sample projects. Let them you are serious as well as competent.
I know you will not believe as you are jobless for a year but TRUTH finally wins.
C# interview questions: - What’s the difference between String and String Builder?
Also visit my site for more C# training.
Sir I've completed b.tech in 2011 ,,,,and searching for a job,,,, I was trained on .NET from NIIT institute ,,,, I've faced some .NET interviews but they are asking for money to pay them,,,,
If someone says pay money to get a job that means they do not need you, you are kind of a baggage on them. Also beware it can be a fraud also. Lately lot of small size software companies and training institutes who are not doing well have turned up to these kind of activities.

When we say we are doing a job, means we are helping company to grow and company pays money in return. So people who are asking for money straight say No No , if that means sitting at home for some time that’s fine, enjoy family.
and other side i am jobless till now and its been 1year,,,and now i don't understand what to do now to see my self as a engineer
If you are jobless for a year you need to see what’s going on wrong. Do connect me personallyfor a mock on .NET interview so that I can personally judge to see what is wrong.
IT market is not so bad. It must be a bit strict for fresher’s but not that horrible as you see. See one is that you are jobless for a year and the other is that in this 1 year you have been to at least 15 interviews and you got till the last round. So if you belong to later part of it that means you are doing well and you should get a job soon.
I personally understand what it means to be at home for a year. But believe me when you get good positions in life ahead you will cherish this struggle and you will be proud of the same.
How about switching to DBA

Courtesy: - http://everydayclimb.files.wordpress.com/
There's a saying in Hindi,DusrokagharSuhanalagtahai( The other side of the grass is always green). .NET, c# has large number of jobs as compared to DBA. Definitely DBA has its own Niche but the numbers of jobs are less. So if for C# you have 100 jobs then for DBA you will have 10. In those 100 c# jobs the number of applicants will be 1000 while in DBA it will be 10.
So one scores high in the number of jobs while the other has less competition. My suggestion would be you have already been trained in NIIT , you are already in full swing of searching a job , stick to .Net for now. You can switch to DBA later when you have a job on hand.
Will a fake 1 year experience help me?

For one Lie you will have to tell 100 Lies ahead. Smaller companies look for people who can code and complete their project. Bigger and mid-level companies look for experience. So start with smaller companies, do not expect sky rocketing salary, be truthful, show your expertise by showing some sample projects. Let them you are serious as well as competent.
I know you will not believe as you are jobless for a year but TRUTH finally wins.
C# interview questions: - What’s the difference between String and String Builder?
Also visit my site for more C# training.
Tuesday, May 15, 2012
C# Training: - Elaborate various types of IIS isolation levels?
IIS has three level of isolation:-
LOW (IIS process):- In this main IIS, process, and ASP.NET application run in same process. So if any one crashes the other is also affected. Example let us say (well this is not possible) I have hosted yahoo, hotmail .amazon and goggle on a single PC. So all application and the IIS process runs on the same process. In case any website crashes, it affects everyone.
Medium (Pooled):- In Medium pooled scenario, the IIS, and web application run in different process. Therefore, in this case there are two processes process1 and process2. In process1, the IIS process is running and in process2, we have all Web application running.
High (Isolated):-In high isolated scenario every process is running is there own process. In below figure there are five processes and every one handling individual application. This consumes heavy memory but has highest reliability.
See the following video on ASP.NET4.0 Redirectpermanent: -
Click to get C# Training
Regards,
Get more C# training stuffs from author's blog
LOW (IIS process):- In this main IIS, process, and ASP.NET application run in same process. So if any one crashes the other is also affected. Example let us say (well this is not possible) I have hosted yahoo, hotmail .amazon and goggle on a single PC. So all application and the IIS process runs on the same process. In case any website crashes, it affects everyone.
Figure: - LOW IIS process scenario
Medium (Pooled):- In Medium pooled scenario, the IIS, and web application run in different process. Therefore, in this case there are two processes process1 and process2. In process1, the IIS process is running and in process2, we have all Web application running.
Figure: - Medium pooled scenario
High (Isolated):-In high isolated scenario every process is running is there own process. In below figure there are five processes and every one handling individual application. This consumes heavy memory but has highest reliability.
Figure: - High isolation scenario
Click to get C# Training
Regards,
Get more C# training stuffs from author's blog
Wednesday, May 2, 2012
Strings are from earth and StringBuilder from mars.
Introduction
I was happily married to string for a long time until I came to know the reality that “Strings are immutable” and not suitable for all scenarios. Recently I was working on a heavy HTML parser application and the program used to go out of memory frequently. The completely HTML parsing logic was using string variables.
After reading around I came to know the main reason was the immutable behavior of string. Immutable means once the data is assigned cannot be changed.
For instance if you are looping using a string variable like the code given below. Every assignment to the string creates new copies of variables and the previous copy is sent for garbage collection. So the below for loop generates different memory copies of data and the recently created is the current value.
Now you must be wondering why this absurd behavior. Any lame person (like me) can conclude this is not efficient and neither looks logical.
The sacrifice for thread safety
Before I start with the solution I wanted to understand why Microsoft team thought about this weird behavior. Thanks to http://stackoverflow.com/questions/2365272/why-net-string-is-immutable things started looking logical.
If you are using string variables in multithreaded scenarios every thread modification will create new copy of memory ensuring that you do not land in to multi-threaded issues. In other words thread safety is built-in by itself when new copies of data are created.
Not all work on ships
The next thing which started itching me is what if my application is not multi-threaded. What if my main motive is to save memory resources and ensure that I do not go out of memory issues?. Here’s comes the hero from mars “StringBuilder”.
“Stringbuilder” are not immutable, in other words if you change the variable data the same memory location is modified. VOW, that looks lot of memory saving during heavy concatenation operation as compared to string.

I wanted to see for myself that earth is flat
As a curios developer it was difficult for me to digest that internally string creates different copies of data. Out of curiosity I downloaded the CLR Profiler and ran two test of code as shown below.
One for string as the below.
string x ="";
for (inti = 0; i< 10000; i++)
{
x = "Shiv"+ x;
}
One for string builder.
StringBuilder x = newStringBuilder();
for (inti = 0; i< 10000; i++)
{
x.Append("Shiv");
}

Watch the allocated bytes, 400235631 bytes is way greaterthan 136597bytes.
Watch the video below for the real demo
If you do not believe what I have written see the actual video demo as follows
Tuesday, March 27, 2012
.Net interview questions: - Explain other ways preferable over finalize for clean up?
Problem with finalize is that garbage collection has to make two rounds in order to remove objects which have finalize methods.
Below figure will make things clear regarding the two rounds of garbage collection rounds performed for the objects having finalized methods.
In this scenario there are three objects Object1, Object2, and Object3. Object2 has the finalize method overridden and remaining objects do not have the finalize method overridden.
Now when garbage collector runs for the first time it searches for objects whose memory has to free. He can see three objects but only cleans the memory for Object1 and Object3. Object2 it pushes to the finalization queue.
Now garbage collector runs for the second time. He see’s there are no objects to be released and then checks for the finalization queue and at this moment, it clears object2 from the memory.
So if you notice that object2 was released from memory in the second round and not first. That is why the best practice is not to write clean up Non.NET resources in Finalize method rather use the DISPOSE.
See the following video in .NET which describes regular expressions & some practical demonstrations: -
Click for more important .NET interview questions
Regards,
Visit for more authors’ blog on interview questions and answers for Dotnet
Below figure will make things clear regarding the two rounds of garbage collection rounds performed for the objects having finalized methods.
Figure: - Garbage collection in actions
In this scenario there are three objects Object1, Object2, and Object3. Object2 has the finalize method overridden and remaining objects do not have the finalize method overridden.
Now when garbage collector runs for the first time it searches for objects whose memory has to free. He can see three objects but only cleans the memory for Object1 and Object3. Object2 it pushes to the finalization queue.
Now garbage collector runs for the second time. He see’s there are no objects to be released and then checks for the finalization queue and at this moment, it clears object2 from the memory.
So if you notice that object2 was released from memory in the second round and not first. That is why the best practice is not to write clean up Non.NET resources in Finalize method rather use the DISPOSE.
See the following video in .NET which describes regular expressions & some practical demonstrations: -
Click for more important .NET interview questions
Regards,
Visit for more authors’ blog on interview questions and answers for Dotnet
Thursday, March 22, 2012
ASP.NET interview questions: - Can you differentiate between trace and debug in ASP.NET?
There is also a fundamental difference in thinking when we want to use trace and when want to debug. Tracing is a process about getting information regarding program's execution. On the other hand debugging is about finding errors in the code.
Debug and trace enables you to monitor the application for errors and exception without VS. NET IDE.
In Debug mode compiler inserts some debugging code inside the executable. As the debugging code is the part of the executable they run on the same thread where the code runs and they do not given you the exact efficiency of the code ( as they run on the same thread). So for every full executable DLL you will see a debug file also as shown in figure ‘Debug Mode’.
See the following video for how to Skip debugging in ASP. NET: -
Click for more ASP. NET Interview questions
Regards,
Visit for more authors’ blog on ASP. NET Interview questions
Debug and trace enables you to monitor the application for errors and exception without VS. NET IDE.
In Debug mode compiler inserts some debugging code inside the executable. As the debugging code is the part of the executable they run on the same thread where the code runs and they do not given you the exact efficiency of the code ( as they run on the same thread). So for every full executable DLL you will see a debug file also as shown in figure ‘Debug Mode’.
Figure: - Debug mode
Trace works in both debug as well as release mode. The main advantage of using trace over debug is to do performance analysis which cannot be done by debug. Trace runs on a different thread thus it does not impact the main code thread.See the following video for how to Skip debugging in ASP. NET: -
Click for more ASP. NET Interview questions
Regards,
Visit for more authors’ blog on ASP. NET Interview questions
Saturday, November 19, 2011
.Net Interview questions: - What is GAC, add/remove an assembly from GAC and how do we make choices between 2 versions of the same assembly?
This .NET interview questions will make you remember the basics of .NET if you are senior person in the .NET industry. For the fresher it is still a hiccup so one can start answering the same as follows: -
About GAC: -
GAC (Global Assembly Cache) is where all shared .NET assembly resides. GAC is used in the following situations: -
You can use the ‘GACUTIL’ tool which comes with visual studio. So to register an assembly in to GAC go to “Visual Studio Command Prompt” and type “gacutil –i (assembly name)”, where (assembly name) is the DLL name of the project.
One you have installed the assembly the DLL can be seen in ‘c:\windows\assembly\’ folder.
When we have many DLL’s to be deployed we need to create setup and deployment package using windows installer. So the common way of deploying GAC DLL in production is by using windows installer.
Making choice between two versions of the same assembly in GAC: -
When we have two version of the same assembly in GAC we need to use binding redirect tag and specify the version we want to use in the new version property as shown in the below “app.config” file.
Get ready to see more basics videos of .NET interview questions on Garbage Collector, Gen 0, 1 & 2 as follows: -
Get more fundamentals stuffs on interview questions and answers for .NET
Regards,
More from author’s blogs on Most asked Dotnet interview question for interview references.
About GAC: -
GAC (Global Assembly Cache) is where all shared .NET assembly resides. GAC is used in the following situations: -
- If the application has to be shared among several application which is in the same computer.
- If the assembly has some special security, requirements like only administrators can remove the assembly. If the assembly is private then a simple delete of assembly the assembly file will remove the assembly.
You can use the ‘GACUTIL’ tool which comes with visual studio. So to register an assembly in to GAC go to “Visual Studio Command Prompt” and type “gacutil –i (assembly name)”, where (assembly name) is the DLL name of the project.
One you have installed the assembly the DLL can be seen in ‘c:\windows\assembly\’ folder.
When we have many DLL’s to be deployed we need to create setup and deployment package using windows installer. So the common way of deploying GAC DLL in production is by using windows installer.
Making choice between two versions of the same assembly in GAC: -
When we have two version of the same assembly in GAC we need to use binding redirect tag and specify the version we want to use in the new version property as shown in the below “app.config” file.
Get ready to see more basics videos of .NET interview questions on Garbage Collector, Gen 0, 1 & 2 as follows: -
Get more fundamentals stuffs on interview questions and answers for .NET
Regards,
More from author’s blogs on Most asked Dotnet interview question for interview references.
Friday, November 4, 2011
.NET interview questions: – CAS model under .NET 4.0
Under .NET 4.0 for CAS there are two major changes are brought in: -
•
Permission granting is no more the work of CAS; it’s now the work of the hosting model. In other words CAS is disabled in .NET 4.0 by default. The host will decide what rights to be given to the .NET assembly.
A new security model i.e. Security transparent model is introduced. The security transparent model puts code in to separate compartments/ boxes as per the risk associated. If you know a code can do something wrong you can compartmentalizethe code as ‘Security transparent’ and if you have a code which you trust you can box them in to ‘Security critical’.
CAS Model: -
Security transparent code is the code which you feel is unsafe and security safe critical code is the code which you feel is safe and has full access to the system. Security transparent code cannot call critical code directly, if they have to then they need to go through security safe critical code.
Figure: - .NET 4.0 CAS model
Also see as detailed video on CAS which explains evidence, permission set & code groups as follows:

Get more for for interview questions and answers for Dotnet complete preparation.
Regards,
Refer author’s other blog for complete Most asked Dotnet interview question
Permission granting is no more the work of CAS; it’s now the work of the hosting model. In other words CAS is disabled in .NET 4.0 by default. The host will decide what rights to be given to the .NET assembly.
A new security model i.e. Security transparent model is introduced. The security transparent model puts code in to separate compartments/ boxes as per the risk associated. If you know a code can do something wrong you can compartmentalizethe code as ‘Security transparent’ and if you have a code which you trust you can box them in to ‘Security critical’.
CAS Model: -
Security transparent code is the code which you feel is unsafe and security safe critical code is the code which you feel is safe and has full access to the system. Security transparent code cannot call critical code directly, if they have to then they need to go through security safe critical code.
Figure: - .NET 4.0 CAS model Also see as detailed video on CAS which explains evidence, permission set & code groups as follows:
Get more for for interview questions and answers for Dotnet complete preparation.
Regards,
Refer author’s other blog for complete Most asked Dotnet interview question
Monday, October 31, 2011
.NET interview questions: - Parse data in Threading.
This is a semi-asked .NET interview questions and has been asked in most of the interviews to check your skills on
parsing data in threading.
As a senior developer you would be interested to know how exactly we can parse data in threading.
Below is the code snippet for simple use of threading: -
Now, when you execute this above code snippet you will see result like below diagram.
The above code snippet seems to be works fine but what if there is a situation that you want to execute for loop according to the data passed by the Thread.
The data can be parsed in threading by the following two ways
1. You can parse the value by defining object variable.
2. You can use Lambda Expression.
So, let’s take the above point’s one by one try to understand it in better manner.
In order to see it practically you just need to follow the following steps.
Step1: - Create a simple Console Application for that just open Visual Studio >> go to >> File >> New >> Project >> Windows >> Select Console Application.
Step2: - let us first prove the point of passing the data using object variables.
Now, simply just add the below code snippet in to program.cs file of your Console Application.
This is how you can parse the data using Object Variables.
Step3: - similarly, let’s take the second point of parsing the data using Lambda Expression.
Now, simply just change your program.cs file code snippet like below code snippet.
Now, when you run your Console Application you will see the result like below diagram.
View the following video on thread, background thread and foreground thread in .NET: -
Click for more Dotnet interview questions and answers
Regards,
Visit for more author’s blog on Most asked Dotnet interview question
As a senior developer you would be interested to know how exactly we can parse data in threading.
Below is the code snippet for simple use of threading: -
class Program
{
static void Main(string[] args)
{
Thread objThread = new Thread(CallMe);
objThread.Start();
}
public static void CallMe()
{
for (int i = 0; i <= 5; i++)
{
Console.WriteLine("Threading.......");
Thread.Sleep(2000);
}
}
}
In the above code snippet you can see that I have created a “CallMe” function which has a for loop and getting executed till the value of “i” is 5 and simply print a line of text to the output screen after every 2 seconds using Thread.Sleep(2000);.Now, when you execute this above code snippet you will see result like below diagram.
The above code snippet seems to be works fine but what if there is a situation that you want to execute for loop according to the data passed by the Thread.
The data can be parsed in threading by the following two ways
1. You can parse the value by defining object variable.
2. You can use Lambda Expression.
So, let’s take the above point’s one by one try to understand it in better manner.
In order to see it practically you just need to follow the following steps.
Step1: - Create a simple Console Application for that just open Visual Studio >> go to >> File >> New >> Project >> Windows >> Select Console Application.
Now, simply just add the below code snippet in to program.cs file of your Console Application.
class Program
{
static void Main(string[] args)
{
Thread objThread = new Thread(CallMe);
//Passing the value 5.
objThread.Start(5);
}
//Created a CallMe function with a Object parameter "k".
public static void CallMe(object k)
{
//creted a int type variable and type caste it.
int j = (int)k;
for (int i = 0; i <= j; i++)
{
Console.WriteLine("Threading.......");
Thread.Sleep(2000);
}
Console.ReadLine();
}
}
Now, just simply execute your console application and will see result like below diagram.This is how you can parse the data using Object Variables.
Step3: - similarly, let’s take the second point of parsing the data using Lambda Expression.
Now, simply just change your program.cs file code snippet like below code snippet.
class Program
{
static void Main(string[] args)
{
//Created a Lambda Expression and parse the value as 7.
Thread objThread = new Thread(() => CallMe(7));
objThread.Start();
}
//Created a CallMe function with a int parameter "k".
public static void CallMe(int k)
{
//Created a int type variable which hold the value of k.
int j = k;
for (int i = 0; i < j; i++)
{
Console.WriteLine("Threading.......");
Thread.Sleep(2000);
}
Console.ReadLine();
}
}
In the below diagram you can see that how I have used the Lambda Expression in order to
parse the data in Threading.Now, when you run your Console Application you will see the result like below diagram.
View the following video on thread, background thread and foreground thread in .NET: -
Click for more Dotnet interview questions and answers
Regards,
Visit for more author’s blog on Most asked Dotnet interview question
Saturday, October 22, 2011
ASP.NET interview questions: - How to make GridView Editable, Updateable and Deleteable in ASP.NET?
Let’s create a simple demonstration to understand the concept of making GridView Editable, Updateable and Deleteable in much better manner.
In order to see it practically you just need to follow the following steps.
Step1: - Create a simple ASP.NET Web Application for that just open Visual Studio >>go to >> File >> New >> Project >> Web >> Select ASP.NET Empty Web Application.
Step2: - Now, simply just add a Web Form to your ASP.NET
Empty Web Application for that just go to >> Solution Explorer >> Right Click on the project name >> Add >> New Item >> Select Web Form.
Now, simply just drag and drop GridView to your Web Form and allow the below
properties to true.
1. Allow AutoGenerateEditButton to True.
2. Allow AutoGenerateDeleteButton to True.
Now, as soon as you set the above two properties you will see the GridView like below diagram.
Step3: - Now, let bind the GridView with Data for that just add the below
code snippet in to your WebForm.aspx.cs file.
//Below variable holds the Connection String.
string str = ConfigurationManager.AppSettings["Connect"];
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridViewData();
}
}
//Created a GridViewData method to bind data to GridView
//from the SQL Server DataBase Table.
public void GridViewData()
{
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "select * from Book";
com.Connection = con;
com.ExecuteNonQuery();
SqlDataAdapter adap = new SqlDataAdapter(com);
DataSet ds = new DataSet();
adap.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
Step4: - This is the most important step while making GridView Editable, Updateable and Deleteable.
Now, simply just add the below Events of the GridView control in to your
Web Application.
1. OnRowEditing.
2. OnRowCancelingEdit.
3. OnRowUpdating.
4. OnRowDeleting.
Step5: - now, just add the below code snippet to make necessary changes on the respective events of the
GridView control.
1. OnRowEditing add the below code snippet.
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GridViewData();
}
2. OnRowCanelingEdit add the below code snippet.
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GridViewData();
}
3. OnRowDeleting add the below code snippet.
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//The below line of code will hold the Cells[1] data of th GridView Control.
string id = GridView1.Rows[e.RowIndex].Cells[1].Text;
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "delete from Book where Book_Id = '"+id+"'";
com.Connection = con;
com.ExecuteNonQuery();
GridViewData();
}
4. OnRowUpdating add the below code snippet.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string bookname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text; string author = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string price = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
string quantity = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand com = new SqlCommand();
com.CommandText = "update Book set Book_Name='" + bookname + "',Book_Author='" + author + "',Book_Price='" + price + "',Book_Quantity='" + quantity + "' where Book_Id= '" + id + "'";
com.Connection = con;
com.ExecuteNonQuery();
GridViewData();
}
Note: - You can modify your code according to your requirements.
Step6: - Now, let’s run your Web Application and see the respective results.
Let’s first see the result for deleting.
The above diagram is my output of the loaded GridView and note that I am going to delete the
circled row data from the GridView control.
Now, as soon as you click on the delete link will see the result like below diagram.
In the above result of diagram you can see that the data has been deleted.
Similarly, let’s see the result for updating the below circled row data in the
GridView control.
Now, as soon as you click on the edit link you will see something like below diagram.
Now, let’s modify the Book_Author Name as Kalim Shaikh and click on the Update link and see whether the data is updated or not.
In the above output diagram you can clearly see that now the Book_Author name is modified to
Kalim Shaikh.
See the following video on ASP.NET Tracing and instrumentation.
Visit for more ASP.NET interview questions.
Regards,
For more author's blog on ASP.NET interview questions
Thursday, October 20, 2011
C# interview questions: - What is the difference between “int” and “Int32” in C#?
What is the difference between “int” and “Int32” in C#?
for more .net and c# interview questions videos click on .NET and c# interview questions
.NET interview questions: - Uses of the Params Keyword in C#.
This is the one the typical .NET interview questions and also the favorable question of the interviewers.
Params: - The params keyword lets you specify a method parameter that takes an argument where the number of arguments is variable.
So, let’s take a scenario where we can have the use of the Params keyword.
Below is the scenario for the same.
Now, simply just run your Application and will see the result like below diagram.
The above code snippet seems to be working fine but what if want to pass multiple arguments at a single instance. So, the Params Keyword helps us to achieve the above scenario in much better manner.
Let’s create a simple example to understand the use of Params Keyword in much better manner.
In order to perform practically you just need to follow the following steps.
Step1: - create a simple Console Application for that just open Visual Studio go to >> File >> New >> Project >> Windows >> Select Console Application.
Step2: - Now, simply just add the below Code Snippet in to Program.cs file of your Console Application.
In the above code snippet you can see that I have created a function “Add” with a Variable “listNumbers” declared using params.
Now, simply just run your Console Application and will see the result like below diagram.
In the above diagram of output you can see the addition of the five numbers using params keyword.
If not understood from the above article, then see the following video on params keyword: -
Get our articles on Most asked Dotnet interview question for preparation.
Regards,
See author’s other important Dotnet interview questions
Params: - The params keyword lets you specify a method parameter that takes an argument where the number of arguments is variable.
So, let’s take a scenario where we can have the use of the Params keyword.
Below is the scenario for the same.
class Program
{
static void Main(string[] args)
{
int y = Add(10, 20);
Console.WriteLine("The Addition of two Numbers is : " + y);
Console.ReadLine();
}
static int Add(int Num1, int Num2)
{
return Num1 + Num2;
}
}
In the above code snippet you can see that I have created a function “Add”
which takes two parameters as “Num1” and “Num2” and return the addition of two numbers. The value for the
parameters are been passed from the Main and it simply print the output to the screen of the “y” variable.Now, simply just run your Application and will see the result like below diagram.
The above code snippet seems to be working fine but what if want to pass multiple arguments at a single instance. So, the Params Keyword helps us to achieve the above scenario in much better manner.
Let’s create a simple example to understand the use of Params Keyword in much better manner.
In order to perform practically you just need to follow the following steps.
Step1: - create a simple Console Application for that just open Visual Studio go to >> File >> New >> Project >> Windows >> Select Console Application.
class Program
{
static void Main(string[] args)
{
//Passed 5 different values.
int y = Add(10,20,30,40,50);
Console.WriteLine("The Addition of Numbers are : " + y);
Console.ReadLine();
}
//Created a listNumbers variable as declared as Params.
static int Add(params int[] listNumbers)
{
int Total = 0;
foreach (int i in listNumbers)
{
Total = i + Total;
}
return Total;
}
}
In the above code snippet you can see that I have created a function “Add” with a Variable “listNumbers” declared using params.
Now, simply just run your Console Application and will see the result like below diagram.
In the above diagram of output you can see the addition of the five numbers using params keyword.
If not understood from the above article, then see the following video on params keyword: -
Get our articles on Most asked Dotnet interview question for preparation.
Regards,
See author’s other important Dotnet interview questions
Wednesday, October 19, 2011
Test yourself for Sharepoint 2010 interviews
This test will help you to check if u will ready for Sharepoint 2010 interviews,try to get 100% marks to ensure you are completely ready.
Best of luck
for more .net and c# interview questions videos click on .NET and c# interview questions
Best of luck
for more .net and c# interview questions videos click on .NET and c# interview questions
.NET and c# interview question practice test - 1
.NET and c# interview question practice test.
for more .net and c# interview questions videos click on .NET and c# interview questions
for more .net and c# interview questions videos click on .NET and c# interview questions
ASP.NET interview questions test :- ASP.NET Page life cycle
Arrange the page life cycle sequence in a proper manner. Hint :- SILVER
for more .net and c# interview questions videos click on .NET and c# interview questions
for more .net and c# interview questions videos click on .NET and c# interview questions
C# and .NET interview questions: - Explain with practical Lambda Expression in C#?
Lambda expression: - A Lambda expression is an anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types.
In simple words Lambda expression is nothing but it is an extended version of delegates or in other words it making delegates simpler.
All Lambda expression uses the lambda operator (=>).
The left side of the lambda operator specifies the input parameters (if any) and the right side hold the expression or statement block.
Let’s create a simple example to understand the concept of Lambda expression in much better manner.
In order to see it practically you just need to follow the following steps.
Step1: - Create a simple Console Application for that just open Visual Studio >> go to >> File >> New >> Project >> Windows >> Select Console Application.


Step2: - Now, simply just add the below code snippet in to program.cs file of your Console Application.
Now, simply just run your console application and you should see the result as shown in the below diagram.

The above code is nice it work’s properly but the concern here is the code complexity; you can see that for a simple line of output we have created extra function, which makes your code little lengthy and not very easy to read.
So Lambda Expression helps us to solve the above problem in simplified manner and making our code more readable and understandable.
Let’s see how exactly Lambda Expression help to solve the above problem for that you just need to follow the following step.
Step3: - Now, just simply modify the program.cs file like below code snippet.
Now, simply just run your console application and will see result like below output diagram.

Watch the following interesting video on threading in C#.NET: -
Get our more important Dotnet interview questions materials.
Regards,
Visit more author's other Most asked Dotnet interview question
In simple words Lambda expression is nothing but it is an extended version of delegates or in other words it making delegates simpler.
All Lambda expression uses the lambda operator (=>).
The left side of the lambda operator specifies the input parameters (if any) and the right side hold the expression or statement block.
Let’s create a simple example to understand the concept of Lambda expression in much better manner.
In order to see it practically you just need to follow the following steps.
Step1: - Create a simple Console Application for that just open Visual Studio >> go to >> File >> New >> Project >> Windows >> Select Console Application.
Step2: - Now, simply just add the below code snippet in to program.cs file of your Console Application.
class Program
{
//created a delegate.
delegate void PointToCallMe(string str);
static void Main(string[] args)
{
//Delegate,which points to the CallMe Function.
PointToCallMe objDelegate = new PointToCallMe(CallMe);
objDelegate.Invoke("Called from Delegate");
Console.ReadLine();
}
public static void CallMe(string str)
{
Console.WriteLine(str);
}
}
In the above code snippet you can see that I have created a function CallMe with a string parameter “str” and I have created a delegate which points toward the CallMe function.Now, simply just run your console application and you should see the result as shown in the below diagram.
The above code is nice it work’s properly but the concern here is the code complexity; you can see that for a simple line of output we have created extra function, which makes your code little lengthy and not very easy to read.
So Lambda Expression helps us to solve the above problem in simplified manner and making our code more readable and understandable.
Let’s see how exactly Lambda Expression help to solve the above problem for that you just need to follow the following step.
Step3: - Now, just simply modify the program.cs file like below code snippet.
class Program
{
//created a delegate.
delegate void PointToCallMe(string str);
static void Main(string[] args)
{
//Lambda Expression.
PointToCallMe objLambda = str => Console.WriteLine(str);
objLambda.Invoke("Called from Lambda");
Console.ReadLine();
}
}
Now, in the above code snippet you can see that I have just eliminated the extra created CallMe function and just written a few line of Lambda Expression, which makes your code more readable and understandable with a few line of code.Now, simply just run your console application and will see result like below output diagram.
Watch the following interesting video on threading in C#.NET: -
Get our more important Dotnet interview questions materials.
Regards,
Visit more author's other Most asked Dotnet interview question
Subscribe to:
Posts (Atom)
























