在c#中,'这个'是什么意思

spi*_*nt0 4 c# c#-4.0

我在这个链接上遇到了这个c#

我无法弄清楚这一行......

public StockTickerHub() : this(StockTicker.Instance) { }
Run Code Online (Sandbox Code Playgroud)

它看起来有点像从基类继承,但我之前没有看到这样this使用过.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;

namespace SignalR.StockTicker
{
    [HubName("stockTickerMini")]
    public class StockTickerHub : Hub
    {
        private readonly StockTicker _stockTicker;

        public StockTickerHub() : this(StockTicker.Instance) { }

        public StockTickerHub(StockTicker stockTicker)
        {
            _stockTicker = stockTicker;
        }

        public IEnumerable<Stock> GetAllStocks()
        {
            return _stockTicker.GetAllStocks();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Art*_*ess 8

它调用同一个类的另一个构造函数.

public class Foo
{
    public Foo() : this (1) { }

    public Foo(int num) 
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

调用new Foo()将调用Foo(1).

更多信息:http://www.dotnetperls.com/this-constructor