Entwickler-Ecke

C# - Die Sprache - Property get/set nicht implementiert --- geht trotzdem!??


maxmeier - Sa 10.07.10 19:07
Titel: Property get/set nicht implementiert --- geht trotzdem!??
Hallo zusammen,

in einem Beispiel bin ich auf folgenden Code gestoßen:


C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
  
    public class CommandViewModel : ViewModelBase
    {
        public CommandViewModel(string displayName, ICommand command)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            base.DisplayName = displayName;
            this.Command = command;
        }

        public ICommand Command { get; private set; }
    }


Man sieht, dass das Command-Property wie in einem Interface deklariert ist - trotzdem ist diese Klasse benutzbar.
Siehe im Konstruktor:

C#-Quelltext
1:
 this.Command = command;                    

Wieso funktioniert das?? Was hab ich da verpasst?

Danke + Grüße
maxmeier


Christian S. - Sa 10.07.10 19:13

Hallo!

In neueren Compilerversionen wird das entsprechende Feld vom Compiler generiert, um Tipparbeit zu sparen :)

Grüße
Christian

//edit: :welcome:


maxmeier - Sa 10.07.10 19:28

So einfach!
Danke!
ciao
maxmeier