5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

C# と TypeScript の比較 (1)

Last updated at Posted at 2013-03-18

個人的必要性に駆られてメモるだけですが。

  • 名前空間(モジュール)とクラス
  • 名前空間のインポート
  • コンストラクタ
  • プロパティ
  • メソッド
  • ドキュメントコメント
CSharp.cs
using Foo.Bar;

namespace Hoge
{
    /// <summary>
    /// Fuga をアレするクラスです。
    /// </summary>
    public class Fuga
    {
        /// <summary>
        /// 何かわからない数値を取得または設定します。
        /// <summary>
        public int Num { get; set; }

        /// <summary>
        /// <see cref="Fuga" /> クラスの新しいインスタンスを初期化します。
        /// <summary>
        public Fuga()
        {
            Console.WriteLine("コンストラクタ");
        }

        /// <summary>
        /// <see cref="Fuga.Num" /> プロパティに指定された数値を加算して文字列として取得します。何に使うのでしょうか。
        /// <summary>
        /// <param name="x">加算する数値。</param>
        /// <returns>よくわからない値。</returns>
        public string GetNumString(int x)
        {
            Piyo.DoSomething();
            return (Num + x).ToString(CultureInfo.InvaliantCulture);
        }
    }
}
TypeScript.ts
module Hoge {

    import bar = Foo.Bar;

    /**
    * Fuga をアレするクラスです。
    */
    export class Fuga {

        /** 何かわからない数値を取得または設定します。 */
        public num : number;

        /**
        * Fuga クラスの新しいインスタンスを初期化します。
        */
        constructor() {
            console.log("コンストラクタ");
        }

        /**
        * Fuga#num プロパティに指定された数値を加算して文字列として取得します。何に使うのでしょうか。
        * @param x 加算する数値。
        */
        public getNumString : string(x : number) {
            // 名前空間(モジュール名)を完全に省略することはできない。
            bar.Piyo.doSomething();
            // メンバの this は省略できない。
            return (this.num + x).toString();
        }
    }
}
5
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?