Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
QuestionUsing Reflection Pin
Mycroft Holmes28-Nov-17 14:21
professionalMycroft Holmes28-Nov-17 14:21 
GeneralRe: Using Reflection Pin
PIEBALDconsult28-Nov-17 14:30
mvePIEBALDconsult28-Nov-17 14:30 
AnswerRe: Using Reflection Pin
User 740747028-Nov-17 16:28
User 740747028-Nov-17 16:28 
GeneralRe: Using Reflection Pin
Mycroft Holmes28-Nov-17 23:02
professionalMycroft Holmes28-Nov-17 23:02 
GeneralRe: Using Reflection Pin
User 740747028-Nov-17 23:37
User 740747028-Nov-17 23:37 
AnswerRe: Using Reflection Pin
BillWoodruff30-Nov-17 0:35
professionalBillWoodruff30-Nov-17 0:35 
GeneralRe: Using Reflection Pin
Mycroft Holmes30-Nov-17 12:01
professionalMycroft Holmes30-Nov-17 12:01 
GeneralRe: Using Reflection Pin
BillWoodruff30-Nov-17 21:48
professionalBillWoodruff30-Nov-17 21:48 
Hi, MyCroft, When I was first discovering (2006) [^] sticking executable code into Dictionaries, it felt very weird. Now, it's even easier since we have Action, Func, and Lambdas, to get us over the Delegate "syntax hump" that confounds many newcomers to C#. Of course, a Delegate lets you have a params list, and Action, and Func, do not.

Consider:
delegate int Calc(params int[] args);

Dictionary<string, Calc> CalcDict = new Dictionary<string, Calc>
{
    {"+", (iary) => iary.Sum()},
    {"-", (iary) =>
        {
            for (var i = 1; i < iary.Length; i++)
            {
                iary[0] -= iary[i];
            }

            return iary[0];
        }
    }
};

// usage example
// int t1 = CalcDict["+"](2, 5, 8, 9);
// int t2 = CalcDict["-"](2, 5 -200, 34)
From my perspective, this "saves you" writing a 'switch statement, and handles variable length input parameters.

But, trust me Smile | :) ... I'm not trying to "sell" you anything, just adding this for the sake of the discussion.
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it.» Claude Levi-Strauss (Tristes Tropiques, 1955)

QuestionI am trying to create and write to a file using one boolean bit at a time. Pin
computerpublic28-Nov-17 13:17
computerpublic28-Nov-17 13:17 
GeneralRe: I am trying to create and write to a file using one boolean bit at a time. Pin
PIEBALDconsult28-Nov-17 14:21
mvePIEBALDconsult28-Nov-17 14:21 
AnswerRe: I am trying to create and write to a file using one boolean bit at a time. Pin
Sascha Lefèvre28-Nov-17 14:52
professionalSascha Lefèvre28-Nov-17 14:52 
AnswerRe: I am trying to create and write to a file using one boolean bit at a time. Pin
Gerry Schmitz29-Nov-17 4:59
mveGerry Schmitz29-Nov-17 4:59 
AnswerRe: I am trying to create and write to a file using one boolean bit at a time. Pin
________________2-Dec-17 23:37
________________2-Dec-17 23:37 
QuestionActive Directory Code Not Returning All Objects Pin
Kevin Marois28-Nov-17 12:37
professionalKevin Marois28-Nov-17 12:37 
AnswerRe: Active Directory Code Not Returning All Objects Pin
Richard Deeming30-Nov-17 8:04
mveRichard Deeming30-Nov-17 8:04 
QuestionHow to use RegEx for AlphaNumeric expressions Pin
Member 1348136128-Nov-17 8:56
Member 1348136128-Nov-17 8:56 
AnswerRe: How to use RegEx for AlphaNumeric expressions Pin
Dave Kreskowiak28-Nov-17 10:49
mveDave Kreskowiak28-Nov-17 10:49 
AnswerRe: How to use RegEx for AlphaNumeric expressions Pin
Dave Kreskowiak28-Nov-17 10:52
mveDave Kreskowiak28-Nov-17 10:52 
AnswerRe: How to use RegEx for AlphaNumeric expressions Pin
Gerry Schmitz29-Nov-17 4:52
mveGerry Schmitz29-Nov-17 4:52 
QuestionEntity FrameWork Question Pin
Kevin Marois28-Nov-17 6:08
professionalKevin Marois28-Nov-17 6:08 
AnswerRe: Entity FrameWork Question Pin
Richard MacCutchan28-Nov-17 6:11
mveRichard MacCutchan28-Nov-17 6:11 
GeneralRe: Entity FrameWork Question Pin
Kevin Marois28-Nov-17 6:15
professionalKevin Marois28-Nov-17 6:15 
GeneralRe: Entity FrameWork Question Pin
Richard MacCutchan28-Nov-17 6:18
mveRichard MacCutchan28-Nov-17 6:18 
GeneralRe: Entity FrameWork Question Pin
Kevin Marois28-Nov-17 6:19
professionalKevin Marois28-Nov-17 6:19 
QuestionParameterized Command Not Adding To DB Pin
MsJane27-Nov-17 8:21
MsJane27-Nov-17 8:21 

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.