C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-09-2009, 03:20 AM   #1
Registered User
 
Join Date: Jun 2009
Posts: 21
Enum List problem

Hi,

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   Reply With Quote
Old 07-09-2009, 04:37 AM   #2
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,119
Exists() expects a predicate (takes an enum, returns a bool). You pass the enum directly.
Use this instead:
Code:
.Exists(Value => (Value == TenderOutcome.Won))
However it's probably better to use the Contains method:
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   Reply With Quote
Old 07-09-2009, 06:26 AM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 03:01 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22