Click here to Skip to main content
15,888,461 members
Home / Discussions / C#
   

C#

 
QuestionDeep Linking between views when using PRISM Pin
Phillip Donegan7-Sep-11 21:46
Phillip Donegan7-Sep-11 21:46 
QuestionEF Repository Questions Pin
Matt U.7-Sep-11 11:00
Matt U.7-Sep-11 11:00 
GeneralRe: EF Repository Questions Pin
PIEBALDconsult7-Sep-11 18:10
mvePIEBALDconsult7-Sep-11 18:10 
GeneralRe: EF Repository Questions Pin
Matt U.8-Sep-11 2:35
Matt U.8-Sep-11 2:35 
GeneralRe: EF Repository Questions Pin
PIEBALDconsult8-Sep-11 3:10
mvePIEBALDconsult8-Sep-11 3:10 
AnswerRe: EF Repository Questions Pin
BobJanova8-Sep-11 3:40
BobJanova8-Sep-11 3:40 
GeneralRe: EF Repository Questions Pin
Matt U.8-Sep-11 4:37
Matt U.8-Sep-11 4:37 
QuestionBetter Way to Search for a Value in a List of KeyValuePairs??? Pin
NickPace7-Sep-11 7:59
NickPace7-Sep-11 7:59 
I have a list of KeyValuePairs:
C#
List<KeyValuePair<Guid, string>> someList;

(And it is populated with several hundred KeyValuePairs of Guids and strings.)

I want to determine if this list of KeyValuePairs contains a certain string value as part of its values. One way to do this is to loop through each KeyValuePair as follows:
C#
bool onList = false;

foreach (KeyValuePair<Guid, string> kvp in someList)
{
    if (kvp.Value.Equals(someStringValue))
    {
        onList = true;
        break;
    }
}

if (onList)
{
    // Do something...
}

However, this seems like a clunky way to perform this check. It seems to me that there must be a way to use the ‘Contains’ method of the List object or Linq to perform this check, but I can’t seem to get the semantics right.

Perhaps something like:
C#
var someValue = someList.Where(kvp => kvp.Value.Equals(someStringValue)); // which doesn’t work

Any suggestions?
-NP

Never underestimate the creativity of the end-user.

AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Pete O'Hanlon7-Sep-11 8:08
mvePete O'Hanlon7-Sep-11 8:08 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Ennis Ray Lynch, Jr.7-Sep-11 8:08
Ennis Ray Lynch, Jr.7-Sep-11 8:08 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
BillWoodruff7-Sep-11 19:37
professionalBillWoodruff7-Sep-11 19:37 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Dan Mos7-Sep-11 8:14
Dan Mos7-Sep-11 8:14 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
NickPace7-Sep-11 9:12
NickPace7-Sep-11 9:12 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Matt U.7-Sep-11 11:02
Matt U.7-Sep-11 11:02 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
NickPace7-Sep-11 12:42
NickPace7-Sep-11 12:42 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Matt U.7-Sep-11 13:12
Matt U.7-Sep-11 13:12 
QuestionRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
MicroVirus8-Sep-11 4:34
MicroVirus8-Sep-11 4:34 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Abhinav S7-Sep-11 8:26
Abhinav S7-Sep-11 8:26 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Ian Shlasko7-Sep-11 10:06
Ian Shlasko7-Sep-11 10:06 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
PIEBALDconsult7-Sep-11 14:25
mvePIEBALDconsult7-Sep-11 14:25 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
Mehdi Gholam7-Sep-11 20:05
Mehdi Gholam7-Sep-11 20:05 
AnswerRe: Better Way to Search for a Value in a List of KeyValuePairs??? [modified] Pin
BillWoodruff7-Sep-11 20:38
professionalBillWoodruff7-Sep-11 20:38 
GeneralRe: Better Way to Search for a Value in a List of KeyValuePairs??? Pin
NickPace8-Sep-11 3:40
NickPace8-Sep-11 3:40 
QuestionC#.net expiration date Pin
classy_dog7-Sep-11 5:30
classy_dog7-Sep-11 5:30 
AnswerRe: C#.net expiration date Pin
GParkings7-Sep-11 5:37
GParkings7-Sep-11 5:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.