我在这个链接中遇到了一些c# http://www.asp.net/signalr/overview/getting-started/tutorial-server-broadcast-with-aspnet-signalr
我无法弄清楚这一行...
public StockTickerHub() : this(StockTicker.Instance) { }
它看起来有点像从基类继承,但我还没见过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();
}
}
}
它调用同一类的另一个构造函数。
public class Foo
{
public Foo() : this (1) { }
public Foo(int num)
{
}
}
Calling new Foo()
将调用Foo(1)
.
更多信息:http://www.dotnetperls.com/this-constructor http://www.dotnetperls.com/this-constructor
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)