“类型'int'的值不能用作默认参数,因为没有标准转换来键入'Reality.Game.Rooms.RoomActorType'”我的C#.exe中出现了错误。< / p>
错误行:
public RoomActor GetActorByReferenceId(int ReferenceId, RoomActorType ReferenceType = 1)
{
lock (this.mActors)
{
foreach (RoomActor actor in this.mActors.Values)
{
if ((actor.Type == ReferenceType) && (actor.ReferenceId == ReferenceId)) /* line of error */
{
return actor;
}
}
}
return null;
}
这是现实&gt;游戏&gt;房间&gt; RoomActorType.cs:
namespace Reality.Game.Rooms
{
using System;
public enum RoomActorType
{
AiBot = 2,
UserCharacter = 1,
}
}
谢谢!
答案 0 :(得分:5)
更改您的方法签名:
public RoomActor GetActorByReferenceId(int ReferenceId, RoomActorType ReferenceType = RoomActorType.UserCharacter)
答案 1 :(得分:1)
RoomActorType ReferenceType = 1)
应该是
RoomActorType ReferenceType = RoomActorType.UserCharacter)
或者如果你真的想使用int do:
RoomActorType ReferenceType = (RoomActorType)1)
如果没有强制转换
,则不能将int用作枚举