how to use idictionary,ienumerable ,list etc

Posted by Gopal_Nivas under C# on 3/19/2012 | Points: 10 | Views : 1589 | Status : [Member] | Replies : 6
hi..

how to use idictionary,ienumerable ,list efficiently in c#..

what is the difference?

need ur suggetsions with examples..

regards
gopal.s




Responses

Posted by: Patel28rajendra on: 3/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

refer this link
http://www.dotnetperls.com/dictionary

http://msdn.microsoft.com/en-us/library/s4ys34ea.aspx

R D Patel

Gopal_Nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

for IEnumerable refer this link

http://www.dotnetperls.com/ienumerable

http://www.c-sharpcorner.com/uploadfile/mode/how-to-use-ienumerable-in-C-Sharp/

R D Patel

Gopal_Nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/19/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

for List

see this link

http://www.dotnetperls.com/list

R D Patel

Gopal_Nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/19/2012 [Member] Silver | Points: 25

Up
0
Down
Hi,
This for your reference:
http://www.eggheadcafe.com/community/csharp/2/10432889/how-to-use-idictionaryienumerable-list-etc.aspx

Thanks,
Sanjay

Gopal_Nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Walshregal on: 12/16/2013 [Member] Starter | Points: 25

Up
0
Down
Better you find the differences first http://net-informations.com/faq/general/dictionary-list.htm c# dictionary vs List.

check this also

http://csharp.net-informations.com/collection/list.htm c# list

http://csharp.net-informations.com/collection/dictionary.htm c# dictionary

walsh


Gopal_Nivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samirbhogayta on: 12/16/2013 [Member] Starter | Points: 25

Up
0
Down
hi..this is your solution

IEnumerable describes behavior, while List is an implementation of that behavior. When you use IEnumerable, you give the compiler a chance to defer work until later, possibly optimizing along the way. If you use ToList() you force the compiler to reify the results right away.

Whenever I'm "stacking" LINQ expressions, I use IEnumerable, because by only specifying the behavior I give LINQ a chance to defer evaluation and possibly optimize the program. Remember how LINQ doesn't generate the SQL to query the database until you enumerate it? Consider this:

public IEnumerable<Animals> AllSpotted()
{
return from a in Zoo.Animals
where a.coat.HasSpots == true
select a;
}

public IEnumerable<Animals> Feline(IEnumerable<Animals> sample)
{
return from a in sample
where a.race.Family == "Felidae"
select a;
}

public IEnumerable<Animals> Canine(IEnumerable<Animals> sample)
{
return from a in sample
where a.race.Family == "Canidae"
select a;
}

Now you have a method that selects an initial sample ("AllSpotted"), plus some filters. So now you can do this:

var Leopards = Feline(AllSpotted());
var Hyenas = Canine(AllSpotted());

So is it faster to use List over IEnumerable? Only if you want to prevent a query from being executed more than once. But is it better overall? Well in the above, Leopards and Hyenas get converted into single SQL queries each, and the database only returns the rows that are relevant. But if we had returned a List from AllSpotted(), then it may run slower because the database could return far more data than is actually needed, and we waste cycles doing the filtering in the client.

In a program, it may be better to defer converting your query to a list until the very end, so if I'm going to enumerate through Leopards and Hyenas more than once, I'd do this:

List<Animals> Leopards = Feline(AllSpotted()).ToList();
List<Animals> Hyenas = Canine(AllSpotted()).ToList();

for more go through this link
http://www.nullskull.com/q/10432889/how-to-use-idictionaryienumerable-list-etc.aspx

SAMIR
Sr. Software Engineer

Gopal_Nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response