关于C# dictionary泛型value值动态添加问题
publicDictionary<String,Seat>seats=newDictionary<String,Seat>();///<summary>///每场增加新的...
public Dictionary<String, Seat> seats = new Dictionary<String, Seat>();
/// <summary>
/// 每场增加新的空座位
/// </summary>
private void addSeats()
{
for (int i = 1; i <=5; i++)
{
for (int j = 1; j <=7; j++)
{
String seatname="set"+i+""+j;
Seat seat;
seat= new Seat(Seatsname, "green", 0);
seats.Add(seat.SeatName, seat);
}
}
}
这段代码系统会报错:(已经存在相同的值名称)
我想知道一个方法能动态改变Seat创建的对象名然后进行动态添加,(像添加键值seatname一样的动态添加到dictionary泛型集合中去)
谢谢大家的帮忙!!! 展开
/// <summary>
/// 每场增加新的空座位
/// </summary>
private void addSeats()
{
for (int i = 1; i <=5; i++)
{
for (int j = 1; j <=7; j++)
{
String seatname="set"+i+""+j;
Seat seat;
seat= new Seat(Seatsname, "green", 0);
seats.Add(seat.SeatName, seat);
}
}
}
这段代码系统会报错:(已经存在相同的值名称)
我想知道一个方法能动态改变Seat创建的对象名然后进行动态添加,(像添加键值seatname一样的动态添加到dictionary泛型集合中去)
谢谢大家的帮忙!!! 展开
展开全部
String seatname="set"+i+""+j;
Seat seat;
seat= new Seat(Seatsname, "green", 0);
seats.Add(seat.SeatName, seat);
改成 String seatname="set"+i+""+j;
seats.Add(SeatName, new Seat(Seatname, "green", 0));
对啦,seat= new Seat(Seatsname, "green", 0);中Seatsname应该是笔误吧,我修改为Seatname
Seat seat;
seat= new Seat(Seatsname, "green", 0);
seats.Add(seat.SeatName, seat);
改成 String seatname="set"+i+""+j;
seats.Add(SeatName, new Seat(Seatname, "green", 0));
对啦,seat= new Seat(Seatsname, "green", 0);中Seatsname应该是笔误吧,我修改为Seatname
展开全部
String seatname="set"+i+""+j;
Seat seat;
seat= new Seat(Seatsname, "green", 0);
seats.Add(seat.SeatName, seat);
改成 String seatname="set"+i+""+j;
seats.Add(SeatName, new Seat(Seatname, "green", 0));
Seat seat;
seat= new Seat(Seatsname, "green", 0);
seats.Add(seat.SeatName, seat);
改成 String seatname="set"+i+""+j;
seats.Add(SeatName, new Seat(Seatname, "green", 0));
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不知道你所谓的动态是什么意思
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询