Benutzer-Werkzeuge

Webseiten-Werkzeuge


csharp:konstruktorabstrakt
no way to compare when less than two revisions

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.


Letzte Überarbeitung
csharp:konstruktorabstrakt [2016/02/26 14:46] – angelegt ronny
Zeile 1: Zeile 1:
 +====== Konstruktoren in Abstrakter Klasse ======
  
 +>>Why is it possible to write constructor for an abstract class in C#?
 +>>As far as I know we can't instantiate an abstract class.. so what is it for?
 +>>You can't instantiate the class, right?
 +>Because there might be a standard way you want to instantiate data in the abstract class. That way you can have classes that inherit from that class call the base constructor.
 +><code>
 +public abstract class A{
 +
 +    private string data;
 +
 +    protected A(string myString){
 +      data = myString;
 +    }
 +
 +}
 +
 +public class B : A {
 +
 +     B(string myString) : base(myString){}
 +
 +}
 +</code>
 +
 +Quelle: [[http://stackoverflow.com/questions/5601777/constructor-of-an-abstract-class-in-c-sharp]]
 +
 +{{tag>[CSharp Konstruktor]}}
csharp/konstruktorabstrakt.txt · Zuletzt geändert: 2016/04/02 00:48 von 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki