Search code examples
c#asp.net-corevisual-studio-codevisual-studio-2015

error A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type


I have an error Error CS1750 A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type 'KtToast.Positions' and error CS1750 A value of type 'int' cannot be used as a default parameter because there are no standard conversions to type 'KtToast.Hosts'

Please Guide me

How can I solve the error and I am also a beginner in C# or There was something wrong in the implementation of the code I created

Thanks

Below is the code I used :


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


Solution

  • See this Microsoft document, when we define public enum Hosts { Screen, Control, FormOwner }, then we can use KtToast.Hosts host = KtToast.Hosts.Control) to set the variable.

    Therefore, your class shall be

    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
    )