![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 21
| Enum List problem I'm trying to use .exists on list of enums but am getting the following error when trying to pass the value of the enumaerated constant: "The best overloaded method match for 'System.Collections.Generic.List<TenderLib_v0._1.T enderOutcome>.Exists(System.Predicate<TenderLib_v0 ._1.TenderOutcome>)' has some invalid arguments" Can someone pleas give me a pointer? Code:
public enum TenderOutcome
{
Undetermined = 0,
Won = 1,
Lost = 2
}
internal void setOutcome(int o)
{
List<TenderOutcome> valuesList= new List<TenderOutcome>();
valuesList = this.OutcomeList; //OutcomeList just returns the values of type TenderOutcome from a dictionary
foreach (TenderOutcome tender in valuesList)
if (!(valuesList.Exists(TenderOutcome.Won)) || (valuesList.Exists(TenderOutcome.Lost)))
...........................
}
|
| scott_ill is offline | |
| | #2 |
| Confused Join Date: Sep 2001 Location: Sweden
Posts: 3,122
| Exists() expects a predicate (takes an enum, returns a bool). You pass the enum directly. Use this instead: Code: .Exists(Value => (Value == TenderOutcome.Won)) Code: .Contains(TenderOutcome.Won)
__________________ MagosX.com Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. |
| Magos is offline | |
| | #3 |
| Registered User Join Date: Jun 2009
Posts: 21
| Great stuff! In the last hour I wrote an extra class to get .Exist to work like .Contains :/ Code: public bool Check(List<TenderOutcome> outcomeList, int outcome)
{
if (OutcomeList.Exists(delegate(TenderOutcome x) { return x.Equals(outcome); }))
{ return true; }
else return false;
}
|
| scott_ill is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Link List math | t014y | C Programming | 17 | 02-20-2009 06:55 PM |
| Problem with linked list ADT and incomplete structure | prawntoast | C Programming | 1 | 04-30-2005 01:29 AM |
| Linked List Help | CJ7Mudrover | C Programming | 9 | 03-10-2004 10:33 PM |
| List class | SilasP | C++ Programming | 0 | 02-10-2002 05:20 PM |
| singly linked list | clarinetster | C Programming | 2 | 08-26-2001 10:21 PM |