Sunday, January 27, 2013

Tip-Convert array to Comma delimited string

I was needed to convert an string array into the comma delimited string and the old way to do that is too with for loop. But I was sure that there should be some ready made function that will do this very easily.

After doing some research I have found string.Join. With the help of this we can easily an array into the comma delimited string.

String.join have two arguments one is separator and other one is either array or enumerable.

Following is a code for that.
namespace ConsoleApplication3
{
    class Program
    {
        static void Main() {
            string[] name = {"Jalpesh", "Vishal", "Tushar", "Gaurang"};
            string commnaDelmietedName = string.Join(",", name);
            System.Console.WriteLine(commnaDelmietedName);
        }
    }
}


Share:
Friday, January 18, 2013

Linq performance with Count() and Any()

Recently I was using resharper to refactor some of my code and found that it was suggesting to use any() extension method instead of count() method in List<T>. I was really keen about performance and found that resharper was right. There is huge performance difference between any() and count() if you are using count() just to check whether list is empty or not.

Difference between Count() and Any():


In Count() method code will traverse all the list and get total number of objects in list while in Any() will return after examining first element in the sequence. So in list where we have many object it will be significant execution time if we use count().
Share:

How to get N row from datatable in C#

Problem:


Recently one of my friend was needed only first three rows of data table and so he asked me and I have multiple solutions for that. So thought it would be great idea to share with you guys.

Possible Solutions to problem:


There are two ways to solve this problem.
  1. With normal for loop
  2. With lamda expression and linq

1. With normal for loop:

Following is code from where we can get 3 rows of data table.
Share:
Thursday, January 17, 2013

New Milestone for Dotnetjalps.com-500000 visits for my blog

Today I got great news from sitemeter.com that my blog http://www.dotnetjalps.com completed 500,000 visitors for my blog. This is a new milestone achieved for this blog and I would like to thank all my blog readers for making this blog this much bigger.

On this occasion I would like to thanks all supporters, friends and my family members who have faith in me and believe that I could do something and this all because of them and my blog readers.
Followings are my statistics for my blog.
Share:
Saturday, January 5, 2013

Search and filters available in visual studio 2012

I have already written lots of post about Visual Studio 2012 features and this post is also going to be part of that series. You can get whole series of post from the following link.

Visual Studio 2012 features

In this post we are going to talk about search and filters provided into the visual studio 2012. There are lots of emphasis there in search and filters in visual studio 2012.You can almost search every thing including errors also. There are different search options are available for that.

Quick launch search in visual studio:


Prior to previous edition in visual studio 2012 there was quick launch search given at the top of the visual studio. From here you can search for anything in solutions and even menu’s also. It will provide you a quick launch for that.
Share:
Friday, January 4, 2013

Lazy<T> in C# 4.0

Before C# 4.0 there was no on demand initialization by default. So at the time of declaration we need to create a value or object will be null or we have to create on demand initialization via coding.. But with C# 4.0 we now have lazy class. As per MSDN it support lazy initialization so it means if we use lazy class then it will initialize the object at the time of demand.

It is very useful for UI responsiveness and other scenario's.  Lazy initialization delays certain initialization and  it’s improve the start-up time of a application. In the earlier framework if we need this kind of functionality we have to do it manually via coding but from C# 4.0 onwards it have Lazy<T> class. With the Help of this we can improve the responsiveness of C# application. Following is a simple example.
Share:
Sunday, December 30, 2012

Lock keyword in C#

As we have written earlier we have now multi-core CPU for our computers and laptops and to utilize that we need to use threading in code. Now if we create thread and access same resource at same time then it will create a problem at that time locking become quite essential in any programming language.

Let’s consider a scenario. We are having a small firm of computers and each computer is shared by two employees and they need to use computer for putting their sales data in excel sheet. So they can not work together at same time and one has to work and other has to wait till first one complete the work. Same situation can be occurred in programming in where we are using same resource for multiple thread.

C# provides locking mechanism via lock keyword. It restricts code from being executed by more then one thread at a time. That is the most reliable way of doing multi threading programming.
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews