Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Code special to MVC

Code special to MVC

Scheduled Pinned Locked Moved .NET (Core and Framework)
18 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Dave Kreskowiak

    Ummm... what's wrong with you? How on this planet did I insult you?

    A guide to posting questions on CodeProject

    Click this: Asking questions is a skill. Seriously, do it.
    Dave Kreskowiak

    L Offline
    L Offline
    larsp777
    wrote on last edited by
    #7

    I think adding the "Seriously, do it" was unnecessary, like I was some idiot. You could have only said "please read this" or something.

    D 1 Reply Last reply
    0
    • D Dave Kreskowiak

      Ummm... what's wrong with you? How on this planet did I insult you?

      A guide to posting questions on CodeProject

      Click this: Asking questions is a skill. Seriously, do it.
      Dave Kreskowiak

      L Offline
      L Offline
      larsp777
      wrote on last edited by
      #8

      Oh, really sorry! Realize now that it was in your signature. again, I apologize.

      D 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        Further to Dave's answer, see: Object and Collection Initializers (C# Programming Guide)[^] How to: Initialize Objects by Using an Object Initializer (C# Programming Guide)[^] Since you're not passing any constructor parameters, you don't even need the empty parentheses after the type name:

        var movie = new Movie {
        Name = "Shrek!"
        };


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        L Offline
        L Offline
        larsp777
        wrote on last edited by
        #9

        As I said I misunderstood. It was the signature, not aimed at me. Yes, he did answer my question and thanks for the further clarification.

        Richard DeemingR 1 Reply Last reply
        0
        • L larsp777

          I think adding the "Seriously, do it" was unnecessary, like I was some idiot. You could have only said "please read this" or something.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #10

          larsp777 wrote:

          I think adding the "Seriously, do it" was unnecessary, like I was some idiot.

          Lighten up, Francis. I hate to tell you this, but that's part of my signature. It shows up on everything I post here. Why do I have that link in there? Because over the 13 years I've been around here I've watched the quality of questions plummet. There are so many "questions" asked around here that don't qualify as questions at all and usually don't have any context to frame the question nor enough detail to answer them. Asking questions really is a skill. As you are/were a teacher: Hi! I am a teaches a course in C# for beginners. you should already know this.

          A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          L 1 Reply Last reply
          0
          • L larsp777

            As I said I misunderstood. It was the signature, not aimed at me. Yes, he did answer my question and thanks for the further clarification.

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #11

            I suggest you revoke your down-vote on Dave's message by clicking the green arrow next to it. :)


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            L 1 Reply Last reply
            0
            • D Dave Kreskowiak

              larsp777 wrote:

              I think adding the "Seriously, do it" was unnecessary, like I was some idiot.

              Lighten up, Francis. I hate to tell you this, but that's part of my signature. It shows up on everything I post here. Why do I have that link in there? Because over the 13 years I've been around here I've watched the quality of questions plummet. There are so many "questions" asked around here that don't qualify as questions at all and usually don't have any context to frame the question nor enough detail to answer them. Asking questions really is a skill. As you are/were a teacher: Hi! I am a teaches a course in C# for beginners. you should already know this.

              A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              L Offline
              L Offline
              larsp777
              wrote on last edited by
              #12

              Well, as said, I realized that it was in your signature and again, I apologize humbly. Yes, I been a teacher for C# beginners but have alot to learn myself obviously :)

              1 Reply Last reply
              0
              • Richard DeemingR Richard Deeming

                I suggest you revoke your down-vote on Dave's message by clicking the green arrow next to it. :)


                "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                L Offline
                L Offline
                larsp777
                wrote on last edited by
                #13

                I will absolutely!

                1 Reply Last reply
                0
                • Richard DeemingR Richard Deeming

                  Further to Dave's answer, see: Object and Collection Initializers (C# Programming Guide)[^] How to: Initialize Objects by Using an Object Initializer (C# Programming Guide)[^] Since you're not passing any constructor parameters, you don't even need the empty parentheses after the type name:

                  var movie = new Movie {
                  Name = "Shrek!"
                  };


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  L Offline
                  L Offline
                  larsp777
                  wrote on last edited by
                  #14

                  Hm, so when do you use this? Feels like everything I thought my students about private variables and getters and setters is obsolete... Here´s something to put in my signature. The more I learn the more I realize how little I know...

                  D P 2 Replies Last reply
                  0
                  • L larsp777

                    Oh, really sorry! Realize now that it was in your signature. again, I apologize.

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #15

                    No problem.

                    A guide to posting questions on CodeProject

                    Click this: Asking questions is a skill. Seriously, do it.
                    Dave Kreskowiak

                    1 Reply Last reply
                    0
                    • L larsp777

                      Hm, so when do you use this? Feels like everything I thought my students about private variables and getters and setters is obsolete... Here´s something to put in my signature. The more I learn the more I realize how little I know...

                      D Offline
                      D Offline
                      Dave Kreskowiak
                      wrote on last edited by
                      #16

                      It doesn't replace the property stuff at all. In fact, this syntax uses those properties. The syntax change is just "shortcut sugar" to avoid having to new up the type and then add a bunch of code to set the properties in multiple statements.

                      A guide to posting questions on CodeProject

                      Click this: Asking questions is a skill. Seriously, do it.
                      Dave Kreskowiak

                      1 Reply Last reply
                      0
                      • L larsp777

                        Hm, so when do you use this? Feels like everything I thought my students about private variables and getters and setters is obsolete... Here´s something to put in my signature. The more I learn the more I realize how little I know...

                        P Offline
                        P Offline
                        Pete OHanlon
                        wrote on last edited by
                        #17

                        It's just syntactic sugar designed to reduce the amount of code you type. It doesn't render any of your previous knowledge obsolete, it's just that it's easier to read something like this:

                        Movie movie = new Movie
                        {
                        Name = "Batman vs Superman",
                        ReleaseYear = 2016,
                        Rating = 4.5
                        }

                        Than it is to read this:

                        Movie movie = new Movie();
                        movie.Name = "Batman vs Superman";
                        movie.ReleaseYear = 2016;
                        movie.Rating = 4.5;

                        It also means you don't have to provide multiple overloaded constructors if you're just providing properties that you want to populate. I don't want to blow your mind, but you can extend this concept to also include collection initialisation as well. Suppose you added a list of actors to your class, you can initialise it like this:

                        Movie movie = new Movie
                        {
                        Name = "Batman vs Superman",
                        ReleaseYear = 2016,
                        Rating = 4.5,
                        Actors = new List<string> { "Ben Afleck", "Jessie Eisenberg", "Gal Gadot", "Henry Cavill" }
                        };

                        This space for rent

                        1 Reply Last reply
                        0
                        • L larsp777

                          Saw this in an example when setting properties. Is this some kind of special ASP.NET MVC syntax?

                          var movie = new Movie() {
                          Name = "Shrek!"
                          };

                          Where Name is a property of the class Movie.

                          U Offline
                          U Offline
                          User 12583363
                          wrote on last edited by
                          #18

                          No; It's already available in c# language called as object initializer. for eg :- Student objstd=new Student(){ Name ="Surya", roll=112, Adress="Hyd" }; So it's available in net framework version 3.0 on word.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups