Click here to Skip to main content
15,905,238 members
Home / Discussions / C#
   

C#

 
AnswerRe: Copy text from console window Pin
Richard MacCutchan9-Sep-19 1:46
mveRichard MacCutchan9-Sep-19 1:46 
AnswerRe: Copy text from console window Pin
OriginalGriff9-Sep-19 1:46
mveOriginalGriff9-Sep-19 1:46 
AnswerRe: Copy text from console window Pin
Gerry Schmitz9-Sep-19 2:58
mveGerry Schmitz9-Sep-19 2:58 
AnswerRe: Copy text from console window Pin
Sharp Ninja9-Sep-19 4:35
Sharp Ninja9-Sep-19 4:35 
GeneralRe: Copy text from console window Pin
Richard MacCutchan9-Sep-19 6:03
mveRichard MacCutchan9-Sep-19 6:03 
GeneralRe: Copy text from console window Pin
Sharp Ninja10-Sep-19 2:57
Sharp Ninja10-Sep-19 2:57 
GeneralRe: Copy text from console window Pin
Richard Deeming10-Sep-19 4:13
mveRichard Deeming10-Sep-19 4:13 
AnswerRe: Copy text from console window Pin
Gene M9-Sep-19 20:31
Gene M9-Sep-19 20:31 
GeneralRe: Copy text from console window Pin
Richard MacCutchan9-Sep-19 21:16
mveRichard MacCutchan9-Sep-19 21:16 
GeneralRe: Copy text from console window Pin
Dave Kreskowiak10-Sep-19 3:13
mveDave Kreskowiak10-Sep-19 3:13 
GeneralRe: Copy text from console window Pin
Gene M10-Sep-19 7:39
Gene M10-Sep-19 7:39 
GeneralRe: Copy text from console window Pin
Dave Kreskowiak10-Sep-19 8:49
mveDave Kreskowiak10-Sep-19 8:49 
GeneralRe: Copy text from console window Pin
Gene M10-Sep-19 11:28
Gene M10-Sep-19 11:28 
GeneralRe: Copy text from console window Pin
Dave Kreskowiak10-Sep-19 11:43
mveDave Kreskowiak10-Sep-19 11:43 
GeneralRe: Copy text from console window Pin
Gene M10-Sep-19 13:03
Gene M10-Sep-19 13:03 
Questioncall enum as argument in Method? Pin
Member 145823347-Sep-19 8:55
Member 145823347-Sep-19 8:55 
AnswerRe: call enum as argument in Method? Pin
Dave Kreskowiak7-Sep-19 10:31
mveDave Kreskowiak7-Sep-19 10:31 
GeneralRe: call enum as argument in Method? Pin
BillWoodruff7-Sep-19 15:36
professionalBillWoodruff7-Sep-19 15:36 
GeneralRe: call enum as argument in Method? Pin
Dave Kreskowiak7-Sep-19 17:21
mveDave Kreskowiak7-Sep-19 17:21 
GeneralRe: call enum as argument in Method? Pin
BillWoodruff7-Sep-19 19:04
professionalBillWoodruff7-Sep-19 19:04 
GeneralRe: call enum as argument in Method? Pin
Member 145823347-Sep-19 16:32
Member 145823347-Sep-19 16:32 
GeneralRe: call enum as argument in Method? Pin
BillWoodruff7-Sep-19 19:02
professionalBillWoodruff7-Sep-19 19:02 
AnswerRe: call enum as argument in Method? Pin
BillWoodruff7-Sep-19 15:29
professionalBillWoodruff7-Sep-19 15:29 
I am going to guess that what you are after is something like this: using a Dictionary whose Key is an Enum value, and whose Value is executable code defined in a deferred form (Func, Action, Delegate, Lambda Expression):
using System;
using System.Collections.Generic;

namespace YourNameSpace
{
    public enum Fruit
    {
        NoFruit, Apple, Orange
    }

    public class FruitCalc
    {
        private Dictionary<Fruit, Func<int, int, Fruit>> CalcFruitDict
            = new Dictionary<Fruit, Func<int, int, Fruit>>
            {
                // lambda notation used here
                {Fruit.Apple, (int napples, int noranges) => napples > noranges ? Fruit.Apple : Fruit.NoFruit },
                {Fruit.Orange, (int napples, int noranges) => napples < noranges ? Fruit.Orange : Fruit.NoFruit },
            };

        public Fruit Calculate(Fruit fruit, int napples, int noranges)
        {
            if (fruit == Fruit.NoFruit)
            {
                throw new InvalidOperationException("Sorry, no fruit means no fruit");
            }

            // check integer parameters for valid range ?

            return CalcFruitDict[fruit](napples, noranges);
        }
    }
}
Usage example:
FruitCalc fcalc = new FruitCalc();

Fruit f1 = fcalc.Calculate(Fruit.Apple, 12, 4);
Fruit f2 = fcalc.Calculate(Fruit.Orange, 14, 24);

Fruit f3 = fcalc.Calculate(Fruit.Apple, 2, 4);
Fruit f4 = fcalc.Calculate(Fruit.Orange, 14, 2);

// force an error
Fruit f5 = fcalc.Calculate(Fruit.NoFruit, 12, 4);
Note: the case where number of apples equals number of oranges is not handled here.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

AnswerRe: call enum as argument in Method? Pin
BillWoodruff7-Sep-19 19:01
professionalBillWoodruff7-Sep-19 19:01 
AnswerRe: call enum as argument in Method? Pin
OriginalGriff7-Sep-19 20:03
mveOriginalGriff7-Sep-19 20:03 

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.