Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
11
Help us understand the problem. What is going on with this article?
@kwst

C#の継承やインターフェース

More than 5 years have passed since last update.

文法的な話です。

継承

  • 継承させる場合、クラス宣言では : を付ける
class Child : Parent {
}
  • 仮想メソッド(overrideさせる時は、virtualをつける)
public virtual void func() {
}
  • baseキーワード(AS3でのsuper)
public override void func() {
    base.func();
}
  • コンストラクタ(親のコンストラクタを使用する場合)
class Child : Parent {
    public Child() : base() {
    }
}
  • protectedは使える

インターフェース

  • 文法はAS3と一緒
interface I {
    void func();
}
class A : I {
    public void func() {
    }
}

抽象クラス

  • インスタンスを生成できない
  • 抽象メソッドを定義できる
  • abstractキーワードを使用する
public abstract class AbstractParent{
    public AbstractParent (){}
    public abstract void func();
}

public class Child : AbstractParent {
    public Child() : base() {
    }
    public override void func() {
    }
}
11
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kwst
Front Engineer

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
11
Help us understand the problem. What is going on with this article?