我正在尝试更改我的代码并实现单例设计模式
我有一堂课叫 Room
protected Room()
{
}
public static Room Instance()
{
if (_instance == null)
{
_instance = new Room();
}
return _instance;
}
public char room { get; set; }
现在我想从主类中分配一些值
Room myRm = Room.Instance();
List<Room> myRoom = new List<Room>();
char[] RoomArray = new char[] { 'A', 'B', 'C', 'D' };
foreach (char c in RoomArray)
{
var theroom = myRm.room = c;
myRoom.Add(theroom); <-----------does not allow me to add some
}
我收到这两个错误
匹配的最佳重载方法
System.Collections.Generic.List<ASR2.Room>.Add(ASR2.Room)
有一些无效参数C:\Project\c-sharp\Assignment1\Asr3\Asr3\Asr.cs
参数 1:无法从 'char' 转换为 'ASR2.Room' C:\Project\c-sharp\Assignment1\Asr3\Asr3\Asr.cs
有人可以帮忙吗?