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.

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.

Friday, October 28, 2011

This is one of the requirements that would come across you many a times while working on .NET projects. Some of the senior developers will find this question very easy but many of the developer friends find it difficult to answer the above question.

So we have tried to give an answer for this
ASP. NET interview questions in the practical form as follows: -
So take a small example to see how exactly we can create a Unique Code like C001, C002……., C00n. In order to see it practically you just need to follow the following steps: -Step1: - Create an 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 in to your Web Application for that just go to
Solution Explorer >> Right click on the Project name>> ADD >> New Item>> Select Web Form.

Step3: - Assume that we have the table of Customer like below diagram.

Step4: - Design your Web Form like below diagram.

Also add a GridView Control to your WebForm.aspx page.

Step5: - This is the most important step for creating Unique Customer code.
Add the below code snippet in to your WebForm.aspx.cs file.

Tuesday, October 25, 2011

An interesting ADO.NET interview questions mostly asked by the interviewer during an interview.
Following are the ways to implement optimistic locking using ADO.NET: -

When we call “Update” method of Data Adapter it handles locking internally. If the Dataset values are not matching with current data in Database, it raises concurrency exception error. We can easily trap this error using Try. Catch block and raise appropriate error message to the user.

Define a Date time stamp field in the table. When actually you are firing the UPDATE SQL statements, compare the current timestamp with one existing in the database. Below is a sample SQL which checks for timestamp before updating and any mismatch in timestamp it will not update the records. This I the best practice used by industries for locking.

Update table1 set field1=@test where Last Timestamp=@Current Timestamp

Check for original values stored in SQL SERVER and actual changed values. In stored procedure check before updating that the old data is same as the current Example in the below shown
SQL before updating field1 we check that is the old field1 value same. If not then some one else has updated and necessary action has to be taken.

Update table1 set field1=@test where field1 = @oldfield1value

Locking can be handled at ADO.NET side or at SQL SERVER side i.e. in stored procedures.

Saturday, October 22, 2011

The process of making GridView Editable, Updateable and Deleteable is almost used in the entire ASP.NET project. So, making GridView Editable, Updateable and Deleteable is one of the most important aspects according to any ASP.NET project.

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.

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.

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: -

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.

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.

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.

Monday, October 17, 2011

This is one of the typical .NET interview questions and has been asked in many of the mid .NET and c# interviews, also the favorable question of the interviewers where they check your skills on casting. Many of our developer friends who are having 1 to 2 years of experience in development also fail to answer this question.

So, let me explain first explain the need of casting.

Let’s create a small and simple demonstration in order to understand the need of
casting in much better manner.

In the above code snippet you can see that I have created an “int” variable “i” and we are trying to move data with decimal part in to the ‘int’ data type.
As you know that the “int” data type can only contain positive or negative value in it and not the decimal part.

Now if you try to compile the code you should see the below error message.

In the above error message diagram you can clearly see that the compiler says that it cannot implicitly convert type ‘double to int’ and are you missing a cast.

So how do we solve the above problem, simple by using CASTING.

Casting: - In simple words casting is nothing but converting data of one data type to another data type.

In order that the above code works you need to specify the integer casting as show in the below code snippet.

static void Main(string[] args)
{
int i = (int) 45.12;
}

When you compile the above code snippet you will find that the compilation has been done successfully like below diagram.

Now the next question which will come to your mind , ‘int’ says he will not take decimals and now the above code is compiling and it’s trying to push decimal data in to INT , so what will get stored in to ‘i” variable.

Now if we put a debug point and see the data in add watch as shown in the below images.

You can clearly see that the value of “i” variable is 45. Which means the fraction part has been eliminated: in other words there has been data loss.

In other words when we do casting there can be loss of data.

Following is the video on regular expressions for preparation on .NET: -

Friday, October 14, 2011

‘Tracelistener’ are objects that get tracing information from the trace classand they output the data to some medium. For instance you can see from thefigure ‘TraceListener’ how it listens to the trace object and outputs the sameto UI, File or a windows event log. There are three different types of‘tracelistener’ first is the ‘defaulttracelistener’ (this outputs the data toUI), second is ‘textwritertracelistener’ (this outputs to a file) and the finalone is ‘Eventlogtracelistener’ which outputs the same to a windows event log.

Figure: -Trace listeners

Below is a snap shot for ‘textwritertracelistener’ and ‘eventlogtracelistener’. Using ‘textwritertracelistener’ we have forwarded the trace’s to ‘ErrorLog.txt’ file and in the second snippet we have used the ‘Eventlogtracelistener’ to forward the trace’s to windows event log.

Step2: - Now add a simple WebForm page in to your Web Application for that just go to >> Solution Explorer >> Right Click on your Project >> Add >> New Item >> Select WebForm.

After adding the WebForm page in to your application, now design your page like below diagram.

Step3: - This is the most important step while using the CSS (Cascading Style Sheet), in this step we just need to add a style sheet for that just go to >> Solution Explorer >> Right Click on your Project >> Add >> New Item >> Select Style Sheet.

Now, let us assume that we have change the background color and text color of the Button control and the TextBox control. In order to achieve the above point we have to add below code snippet in to your StyleSheet1.css file.

Subscription Package for fundamentals and Interview preparation

which consist of .NET, C#, ASP.NET, SQL Server, WCF, Design Patterns, SilverLight, LINQ, SharePoint, Azure videos read details of subscription Also want to inquire more then call us on +91-22-66752917/mail us on questpond@questpond.com. Simply click to .