0
0

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#】【文法】ジェネリック

Last updated at Posted at 2019-10-03

    // 自前のジェネリッククラス
    class Practice9_2
    {
        static void Main(string[] args)
        {
            var s = new Sample<int, float>(15, 20.0f);
            s.Show();
            s = new Sample<int, float>();
            s.Show();
        }
        
    }

    // ジェネリックなクラスを定義する。
    class Sample<T1, T2>
    {
        private T1 _item1 { get; set; }
        private T2 _item2 { get; set; }

        public Sample()
        {
            this._item1 = default(T1);
            this._item2 = default(T2);
        }

        public Sample(T1 t1, T2 t2)
        {
            this._item1 = t1;
            this._item2 = t2;
        }
        public void Show ()
        {
            Console.WriteLine(_item1.ToString());
            Console.WriteLine(_item2.ToString());
        }

        public (T1, T2) getT()
        {
            return (_item1, _item2);
        }
    }
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?