Is there a conceptual reason why calling a method with a dynamic parameter always returns dynamic?Why is it important to override GetHashCode when Equals method is overridden?Convert Dynamic Type to ListWhy does ++[[]][+[]]+[+[]] return the string “10”?Using LINQ with dynamic variables in C#Can not pass dynamic argument and lambda to the methodCannot use a lambda expressionWhat is the difference between the two Casts for a Dynamic Object in Linq?Cannot use a lambda expression as an argument to a dynamically dispatchederror CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operationError passing both a dynamic object and an Action to a function
Different PCB color ( is it different material? )
Term for checking piece whose opponent daren't capture it
How to detach yourself from a character you're going to kill?
How to properly maintain eye contact with people that have distinctive facial features?
Draw a checker pattern with a black X in the center
Strange math syntax in old basic listing
Why does the UK have more political parties than the US?
Is there an evolutionary advantage to having two heads?
Rotated Position of Integers
Does `declare -a A` create an empty array `A` in Bash?
What does "tea juice" mean in this context?
What is game ban VS VAC ban in steam?
In what episode of TOS did a character on the bridge make a comment about raising the number 1 to some power?
How can I offer a test ride while selling a bike?
Can an old DSLR be upgraded to match modern smartphone image quality
If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?
Possible nonclassical ion from a bicyclic system
Is there an explanation for Austria's Freedom Party virtually retaining its vote share despite recent scandal?
Can you move on your turn, and then use the Ready Action to move again on another creature's turn?
Select row of data if next row contains zero
How to prevent bad sectors?
Intuition behind eigenvalues of an adjacency matrix
When was the expression "Indian file" first used in English?
What does "Marchentalender" on the front of a postcard mean?
Is there a conceptual reason why calling a method with a dynamic parameter always returns dynamic?
Why is it important to override GetHashCode when Equals method is overridden?Convert Dynamic Type to ListWhy does ++[[]][+[]]+[+[]] return the string “10”?Using LINQ with dynamic variables in C#Can not pass dynamic argument and lambda to the methodCannot use a lambda expressionWhat is the difference between the two Casts for a Dynamic Object in Linq?Cannot use a lambda expression as an argument to a dynamically dispatchederror CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operationError passing both a dynamic object and an Action to a function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I can imagine this would be a problem with multiple overloads, but (besides Linq) a big part of the code probably has only one overload.
When there is only one overload it can save extra casting boilerplate, avoiding errors like Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
in situations.
Of course you could argue that when you add an overload at a later stage the code would i.e. start triggering the above compiler error again. But then again - adding overloads can also break typed behavior (with i.e. multiple interfaces).
Is this just not a priority (for now) or am I missing some conceptual problem? I'm asking this to learn more about language design.
static int MapLolCats(int amountOfLolcats, Func<dynamic,int> mappingFunction)
return mappingFunction(amountOfLolcats);
// This works as expected
var amountOfLegs = MapLolCats(5, x => x * 4);
// This creates a compilation error (despite you could deduct what is meant, because there is only one overload)
// Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
dynamic jsonValue = 5;
var amountOfLegs = MapLolCats(jsonValue, x => x * 4);
c# syntax compilation dynamic-keyword
add a comment |
I can imagine this would be a problem with multiple overloads, but (besides Linq) a big part of the code probably has only one overload.
When there is only one overload it can save extra casting boilerplate, avoiding errors like Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
in situations.
Of course you could argue that when you add an overload at a later stage the code would i.e. start triggering the above compiler error again. But then again - adding overloads can also break typed behavior (with i.e. multiple interfaces).
Is this just not a priority (for now) or am I missing some conceptual problem? I'm asking this to learn more about language design.
static int MapLolCats(int amountOfLolcats, Func<dynamic,int> mappingFunction)
return mappingFunction(amountOfLolcats);
// This works as expected
var amountOfLegs = MapLolCats(5, x => x * 4);
// This creates a compilation error (despite you could deduct what is meant, because there is only one overload)
// Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
dynamic jsonValue = 5;
var amountOfLegs = MapLolCats(jsonValue, x => x * 4);
c# syntax compilation dynamic-keyword
The code you show doesn't have any compilation errors, I don't understand this question.
– DavidG
Mar 24 at 10:06
Hi @DavidG, I've updated the example - hopefully it's more clear what I mean
– Dirk Boer
Mar 24 at 10:14
Have you considered usingFunc<dynamic, int> g = x => x * 4;
?
– mjwills
Mar 24 at 11:36
add a comment |
I can imagine this would be a problem with multiple overloads, but (besides Linq) a big part of the code probably has only one overload.
When there is only one overload it can save extra casting boilerplate, avoiding errors like Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
in situations.
Of course you could argue that when you add an overload at a later stage the code would i.e. start triggering the above compiler error again. But then again - adding overloads can also break typed behavior (with i.e. multiple interfaces).
Is this just not a priority (for now) or am I missing some conceptual problem? I'm asking this to learn more about language design.
static int MapLolCats(int amountOfLolcats, Func<dynamic,int> mappingFunction)
return mappingFunction(amountOfLolcats);
// This works as expected
var amountOfLegs = MapLolCats(5, x => x * 4);
// This creates a compilation error (despite you could deduct what is meant, because there is only one overload)
// Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
dynamic jsonValue = 5;
var amountOfLegs = MapLolCats(jsonValue, x => x * 4);
c# syntax compilation dynamic-keyword
I can imagine this would be a problem with multiple overloads, but (besides Linq) a big part of the code probably has only one overload.
When there is only one overload it can save extra casting boilerplate, avoiding errors like Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type.
in situations.
Of course you could argue that when you add an overload at a later stage the code would i.e. start triggering the above compiler error again. But then again - adding overloads can also break typed behavior (with i.e. multiple interfaces).
Is this just not a priority (for now) or am I missing some conceptual problem? I'm asking this to learn more about language design.
static int MapLolCats(int amountOfLolcats, Func<dynamic,int> mappingFunction)
return mappingFunction(amountOfLolcats);
// This works as expected
var amountOfLegs = MapLolCats(5, x => x * 4);
// This creates a compilation error (despite you could deduct what is meant, because there is only one overload)
// Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
dynamic jsonValue = 5;
var amountOfLegs = MapLolCats(jsonValue, x => x * 4);
c# syntax compilation dynamic-keyword
c# syntax compilation dynamic-keyword
edited Mar 24 at 10:15
Dirk Boer
asked Mar 24 at 10:02


Dirk BoerDirk Boer
2,32393872
2,32393872
The code you show doesn't have any compilation errors, I don't understand this question.
– DavidG
Mar 24 at 10:06
Hi @DavidG, I've updated the example - hopefully it's more clear what I mean
– Dirk Boer
Mar 24 at 10:14
Have you considered usingFunc<dynamic, int> g = x => x * 4;
?
– mjwills
Mar 24 at 11:36
add a comment |
The code you show doesn't have any compilation errors, I don't understand this question.
– DavidG
Mar 24 at 10:06
Hi @DavidG, I've updated the example - hopefully it's more clear what I mean
– Dirk Boer
Mar 24 at 10:14
Have you considered usingFunc<dynamic, int> g = x => x * 4;
?
– mjwills
Mar 24 at 11:36
The code you show doesn't have any compilation errors, I don't understand this question.
– DavidG
Mar 24 at 10:06
The code you show doesn't have any compilation errors, I don't understand this question.
– DavidG
Mar 24 at 10:06
Hi @DavidG, I've updated the example - hopefully it's more clear what I mean
– Dirk Boer
Mar 24 at 10:14
Hi @DavidG, I've updated the example - hopefully it's more clear what I mean
– Dirk Boer
Mar 24 at 10:14
Have you considered using
Func<dynamic, int> g = x => x * 4;
?– mjwills
Mar 24 at 11:36
Have you considered using
Func<dynamic, int> g = x => x * 4;
?– mjwills
Mar 24 at 11:36
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322605%2fis-there-a-conceptual-reason-why-calling-a-method-with-a-dynamic-parameter-alway%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322605%2fis-there-a-conceptual-reason-why-calling-a-method-with-a-dynamic-parameter-alway%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The code you show doesn't have any compilation errors, I don't understand this question.
– DavidG
Mar 24 at 10:06
Hi @DavidG, I've updated the example - hopefully it's more clear what I mean
– Dirk Boer
Mar 24 at 10:14
Have you considered using
Func<dynamic, int> g = x => x * 4;
?– mjwills
Mar 24 at 11:36