Tuesday 15 March 2011

c# - Finding Dictionary values based on object/type members -



c# - Finding Dictionary values based on object/type members -

i have dictionary defined below,

dictionary<string, sampleobject> test = new dictionary<string, sampleobject>(); test.add("a", null); test.add("b", new sampleobject() { id = "1", value1 = "bbbbb1", value2 = "bbbbb2" }); test.add("c", new sampleobject() { id = "1", value1 = "cdcdcd1", value2 = "cdcdcd2" }); test.add("d", new sampleobject() { id = "2", value1 = "xxffa", value2 = "xxffb" });

how list/count object/type null?

how list/count object/type property (id = 1)?

i tried , getting error.

var ones = test.where(t => t.value.id.equals("1"));

you need weed out nulls first:

var nulls = test.count(c => c.value == null); var ones = test.count(c => c.value != null && c.value.id == "1");

c#

No comments:

Post a Comment