简体   繁体   English

类型为'int'的值不能用作默认参数,因为没有标准转换来键入C#

[英]A value of type 'int' cannot be used as a default parameter because there are no standards conversions to type C#

"A value of type 'int' cannot be used as a default parameter because there are no standards conversions to type 'Reality.Game.Rooms.RoomActorType'" is there error I'm getting within my C#.exe. “类型'int'的值不能用作默认参数,因为没有标准转换来键入'Reality.Game.Rooms.RoomActorType'”我的C#.exe中出现了错误。

The line(s) of error: 错误的行:

 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;
   }

Here's Reality>Game>Rooms>RoomActorType.cs: 这是现实>游戏>房间> RoomActorType.cs:

namespace Reality.Game.Rooms
{
using System;

public enum RoomActorType
  {
    AiBot = 2,
    UserCharacter = 1,
  }
}

Thanks! 谢谢!

更改方法签名:

public RoomActor GetActorByReferenceId(int ReferenceId, RoomActorType ReferenceType = RoomActorType.UserCharacter)
RoomActorType ReferenceType = 1)

should be 应该

RoomActorType ReferenceType = RoomActorType.UserCharacter)

or if you really want to use int do: 或者如果你真的想使用int do:

RoomActorType ReferenceType = (RoomActorType)1)

You can not use int as enum without casting 如果没有强制转换,则不能将int用作枚举

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型为“<null>”的值不能用作默认参数,因为没有标准转换来键入“T” - A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'T' 值类型字符串不能用作默认参数 - Value type string cannot be used as default parameter 泛型参数的C#类型转换 - C# Type Conversions for Generics Parameter 为什么类型为null的值不能用作double类型的默认参数? - Why a value of type null cannot be used as a default parameter with type double? 不能使用类型为&#39;int&#39;的值 - A value of type 'int' cannot be used '?' 类型的值不能用作默认参数 | .net 6 与 .net 4.8 - A value of type '?' cannot be used as a default parameter | .net 6 vs .net 4.8 C#动态类型转换 - C# dynamic type conversions C#无法将匿名方法转换为int类型,因为它不是委托类型 - C# cannot convert anonymous method to type int because it's not a delegate type C#ADO.Net无法确定条件表达式的类型,因为DBNull.Value与int之间没有隐式转换 - C# ADO.Net Type of conditional expression cannot be determined because there is no implicit conversion between DBNull.Value and int C#不能跨程序集边界使用,因为它具有嵌入式互操作类型的泛型类型参数 - C# Cannot be used across assembly boundaries because it has a generic type parameters that is an embedded interop type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM