错误“int”类型的值不能用作默认参数,因为没有到类型的标准转换

问题描述 投票:0回答:1

我有一个错误

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

c# visual-studio-code visual-studio-2015
1个回答
0
投票

参见这个微软文档,当我们定义了

 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)

© www.soinside.com 2019 - 2024. All rights reserved.