Unity 错误 CS0103:当前上下文中不存在名称“”
Unity error CS0103: The name `' does not exist in the current context
我有一个像这样的通用 class:
public class Connection<T> where T: Stream
{
protected T _stream;
protected TcpClient _client;
public void Connect(){/*Do somthing*/}
public void Disconnect(){/*Do somthing*/}
public void Reconnect()
{
Disconnect();
Connect();
}
}
我使用 VisualStudio 作为编辑器,它没有错误,但在统一编辑器控制台中显示:
error CS0103: The name 'Disconnect' does not exist in the current context
和
error CS0103: The name 'Connect' does not exist in the current context
错误行在 Reconnect()
函数中。
如果我从这个 class 中删除泛型,它没有任何错误。
这是一个错误还是我错过了什么?
我是这样修复的:
public abstract class BaseConnection<T>
{
protected T _stream;
protected TcpClient _client;
public abstract void Connect();
public abstract void Disconnect();
}
public class Connection<T> : BaseConnection<T>
where T: Stream
{
public override void Connect(){/*Do somthing*/}
public override void Disconnect(){/*Do somthing*/}
public void Reconnect()
{
Disconnect();
Connect();
}
}
我有一个像这样的通用 class:
public class Connection<T> where T: Stream
{
protected T _stream;
protected TcpClient _client;
public void Connect(){/*Do somthing*/}
public void Disconnect(){/*Do somthing*/}
public void Reconnect()
{
Disconnect();
Connect();
}
}
我使用 VisualStudio 作为编辑器,它没有错误,但在统一编辑器控制台中显示:
error CS0103: The name 'Disconnect' does not exist in the current context
和
error CS0103: The name 'Connect' does not exist in the current context
错误行在 Reconnect()
函数中。
如果我从这个 class 中删除泛型,它没有任何错误。 这是一个错误还是我错过了什么?
我是这样修复的:
public abstract class BaseConnection<T>
{
protected T _stream;
protected TcpClient _client;
public abstract void Connect();
public abstract void Disconnect();
}
public class Connection<T> : BaseConnection<T>
where T: Stream
{
public override void Connect(){/*Do somthing*/}
public override void Disconnect(){/*Do somthing*/}
public void Reconnect()
{
Disconnect();
Connect();
}
}