the title is a mouthful and not even sure it's accurate (couldn't make much sense of this), so I'll try to explain what I'd like to accomplish in C# by using equivalent javascript. Any suggestion as to what I should title this question is very much welcome.
In C#, say I have defined this function:
Func<string, string> getKey = entity => {
switch(entity) {
case "a":
return "foo";
case "b":
return "bar";
default:
return "baz";
}
};
string key = getKey(/* "a", "b", or something else */);
Now suppose I don't want to define the getKey function explicitly, but use it anonymously as I would in this equivalent javascript snippet:
string key = (function(entity) {
switch(entity) {
case "a":
return "foo";
case "b":
return "bar";
default:
return "baz";
}
}(/* "a", "b", or something else */));
How would I go about writing that in C#? I tried:
string key = (entity => {
switch(entity) {
case "a":
return "foo";
case "b":
return "bar";
default:
return "baz";
}
})(/* "a", "b", or something else */);
but I get syntax error CS0149: Method name expected.
Thanks in advance, cheers.