Enum List problem

This is a discussion on Enum List problem within the C# Programming forums, part of the General Programming Boards category; Hi, I'm trying to use .exists on list of enums but am getting the following error when trying to pass ...

  1. #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)))
    ...........................
             }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.

  3. #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;
    
            }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 02:29 AM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. List class
    By SilasP in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2002, 05:20 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 11:21 PM

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