.NET interview questions: – How to 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: –

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.

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.

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));
        //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++)

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


Visit for more author’s blog on Most asked Dotnet interview questions


About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , , , . Bookmark the permalink.

2 Responses to .NET interview questions: – How to parse data in Threading?

  1. Pingback: DotNetShoutout

  2. Pingback: .NET interview questions: – How to parse data... | .NET | Syngu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s