dynamic keyword affects return typeWhat is the yield keyword used for in C#?What's the difference between the 'ref' and 'out' keywords?Func delegate with no return typeType Checking: typeof, GetType, or is?Deserialize JSON into C# dynamic object?Dynamic + linq compilation errorDifferent return type for same method of a base classdynamic keyword with ExpandoObject to attach and remove propertiesWhy won't the DLR (dynamic) bind to a private type?What is the difference between .NET Core and .NET Standard Class Library project types?

How do I repair my stair bannister?

Visiting the UK as unmarried couple

anything or something to eat

Did arcade monitors have same pixel aspect ratio as TV sets?

What is the difference between "Do you interest" and "...interested in" something?

Proving a function is onto where f(x)=|x|.

Indicating multiple different modes of speech (fantasy language or telepathy)

Greco-Roman egalitarianism

Reply 'no position' while the job posting is still there

Is a model fitted to data or is data fitted to a model?

What's the difference between 違法 and 不法?

Is camera lens focus an exact point or a range?

Divine apple island

Find last 3 digits of this monster number

Transformation of random variables and joint distributions

Is there a conventional notation or name for the slip angle?

Did US corporations pay demonstrators in the German demonstrations against article 13?

How should I respond when I lied about my education and the company finds out through background check?

Drawing a topological "handle" with Tikz

About a little hole in Z'ha'dum

How to decide convergence of Integrals

How must one send away the mother bird?

Has Darkwing Duck ever met Scrooge McDuck?

What major Native American tribes were around Santa Fe during the late 1850s?



dynamic keyword affects return type


What is the yield keyword used for in C#?What's the difference between the 'ref' and 'out' keywords?Func delegate with no return typeType Checking: typeof, GetType, or is?Deserialize JSON into C# dynamic object?Dynamic + linq compilation errorDifferent return type for same method of a base classdynamic keyword with ExpandoObject to attach and remove propertiesWhy won't the DLR (dynamic) bind to a private type?What is the difference between .NET Core and .NET Standard Class Library project types?













1















I'm not entirley sure why the following code compiles



namespace ConsoleApp13

public class Person



class Program

static void Main(string[] args)

dynamic expand = new ExpandoObject();
List<Person> people = GetPerson(expand);



public static Person GetPerson(int item)

return new Person();






Why does the dynamic keyword impact the return type. It's like the compiler give's up on type checking as soon as dynamic is introduced. Is this expected behavior?










share|improve this question




























    1















    I'm not entirley sure why the following code compiles



    namespace ConsoleApp13

    public class Person



    class Program

    static void Main(string[] args)

    dynamic expand = new ExpandoObject();
    List<Person> people = GetPerson(expand);



    public static Person GetPerson(int item)

    return new Person();






    Why does the dynamic keyword impact the return type. It's like the compiler give's up on type checking as soon as dynamic is introduced. Is this expected behavior?










    share|improve this question


























      1












      1








      1








      I'm not entirley sure why the following code compiles



      namespace ConsoleApp13

      public class Person



      class Program

      static void Main(string[] args)

      dynamic expand = new ExpandoObject();
      List<Person> people = GetPerson(expand);



      public static Person GetPerson(int item)

      return new Person();






      Why does the dynamic keyword impact the return type. It's like the compiler give's up on type checking as soon as dynamic is introduced. Is this expected behavior?










      share|improve this question
















      I'm not entirley sure why the following code compiles



      namespace ConsoleApp13

      public class Person



      class Program

      static void Main(string[] args)

      dynamic expand = new ExpandoObject();
      List<Person> people = GetPerson(expand);



      public static Person GetPerson(int item)

      return new Person();






      Why does the dynamic keyword impact the return type. It's like the compiler give's up on type checking as soon as dynamic is introduced. Is this expected behavior?







      c# .net dynamic .net-core






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 21 at 23:43









      ArunPratap

      2,20621028




      2,20621028










      asked Mar 21 at 13:45









      Steven YatesSteven Yates

      1,2081943




      1,2081943






















          1 Answer
          1






          active

          oldest

          votes


















          3















          Is this expected behavior?




          Yes. Almost anything you do that involves a dynamic value ends up with a compile-time type of dynamic. Note that binding is performed dynamically, so even though in this specific case you've only got one GetPerson method, in the more general case of method invocation, overloads could be present at execution time that aren't present at compile-time, with different return types.



          There are a few operations which don't end up with a dynamic type:



          • Casting (e.g. (string) dynamicValue)

          • The is operator (e.g. dynamicValue is string)

          • The as operator (e.g. dynamicValue as string

          • Constructor calls (e.g. new Foo(dynamicValue))





          share|improve this answer























          • Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

            – Steven Yates
            Mar 21 at 16:29










          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
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281869%2fdynamic-keyword-affects-return-type%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3















          Is this expected behavior?




          Yes. Almost anything you do that involves a dynamic value ends up with a compile-time type of dynamic. Note that binding is performed dynamically, so even though in this specific case you've only got one GetPerson method, in the more general case of method invocation, overloads could be present at execution time that aren't present at compile-time, with different return types.



          There are a few operations which don't end up with a dynamic type:



          • Casting (e.g. (string) dynamicValue)

          • The is operator (e.g. dynamicValue is string)

          • The as operator (e.g. dynamicValue as string

          • Constructor calls (e.g. new Foo(dynamicValue))





          share|improve this answer























          • Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

            – Steven Yates
            Mar 21 at 16:29















          3















          Is this expected behavior?




          Yes. Almost anything you do that involves a dynamic value ends up with a compile-time type of dynamic. Note that binding is performed dynamically, so even though in this specific case you've only got one GetPerson method, in the more general case of method invocation, overloads could be present at execution time that aren't present at compile-time, with different return types.



          There are a few operations which don't end up with a dynamic type:



          • Casting (e.g. (string) dynamicValue)

          • The is operator (e.g. dynamicValue is string)

          • The as operator (e.g. dynamicValue as string

          • Constructor calls (e.g. new Foo(dynamicValue))





          share|improve this answer























          • Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

            – Steven Yates
            Mar 21 at 16:29













          3












          3








          3








          Is this expected behavior?




          Yes. Almost anything you do that involves a dynamic value ends up with a compile-time type of dynamic. Note that binding is performed dynamically, so even though in this specific case you've only got one GetPerson method, in the more general case of method invocation, overloads could be present at execution time that aren't present at compile-time, with different return types.



          There are a few operations which don't end up with a dynamic type:



          • Casting (e.g. (string) dynamicValue)

          • The is operator (e.g. dynamicValue is string)

          • The as operator (e.g. dynamicValue as string

          • Constructor calls (e.g. new Foo(dynamicValue))





          share|improve this answer














          Is this expected behavior?




          Yes. Almost anything you do that involves a dynamic value ends up with a compile-time type of dynamic. Note that binding is performed dynamically, so even though in this specific case you've only got one GetPerson method, in the more general case of method invocation, overloads could be present at execution time that aren't present at compile-time, with different return types.



          There are a few operations which don't end up with a dynamic type:



          • Casting (e.g. (string) dynamicValue)

          • The is operator (e.g. dynamicValue is string)

          • The as operator (e.g. dynamicValue as string

          • Constructor calls (e.g. new Foo(dynamicValue))






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 21 at 13:49









          Jon SkeetJon Skeet

          1094k69579788464




          1094k69579788464












          • Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

            – Steven Yates
            Mar 21 at 16:29

















          • Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

            – Steven Yates
            Mar 21 at 16:29
















          Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

          – Steven Yates
          Mar 21 at 16:29





          Thanks! I ended up looking deeper at the IL and then understood what was going on but thank you got the explanation, much appreciated

          – Steven Yates
          Mar 21 at 16:29



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281869%2fdynamic-keyword-affects-return-type%23new-answer', 'question_page');

          );

          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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript