我有一个错误
Error CS1750 A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type 'KtToast.Positions'
和 error CS1750 A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type 'KtToast.Hosts'
请指导我
我该如何解决该错误,我也是 C# 初学者,或者我创建的代码的实现出现问题
谢谢
下面是我使用的代码:
namespace WindowsFormsApplication2
{
public sealed class KtToast : Component
{
public KtToast.SnackbarResult Show(Form owner, string message, KtToast.MessageTypes type = 0, int duration = 3000, string action = "", KtToast.Positions position = 1, KtToast.Hosts host = 2)
{
}
public enum SnackbarResult
{
AutoClosed,
UserClosed,
ActionClicked
}
public enum Hosts
{
Screen,
Control,
FormOwner
}
public enum Positions
{
TopLeft,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight,
Custom
}
public enum MessageTypes
{
Information,
Success,
Warning,
Error
}
}
}
参见这个微软文档,当我们定义了
public enum Hosts { Screen, Control, FormOwner }
之后,我们就可以使用KtToast.Hosts host = KtToast.Hosts.Control)
来设置变量。
因此,你的班级应该是
public KtToast.SnackbarResult Show(Form owner, string message, KtToast.MessageTypes type = KtToast.MessageTypes.Information, int duration = 3000, string action = "", KtToast.Positions position = KtToast.Positions.TopCenter, KtToast.Hosts host = KtToast.Hosts.FormOwner)