Pass in an enum as a method parameter

前端 未结 4 1685
北海茫月
北海茫月 2020-12-30 18:52

I have declared an enum:

public enum SupportedPermissions
{
    basic,
    repository,
    both
}

I also have a POCO like this:

<         


        
4条回答
  •  遥遥无期
    2020-12-30 19:35

    First change the method parameter Enum supportedPermissions to SupportedPermissions supportedPermissions.

    Then create your file like this

    file = new File
    {  
        Name = name,
        Id = id,
        Description = description,
        SupportedPermissions = supportedPermissions
    };
    

    And the call to your method should be

    CreateFile(id, name, description, SupportedPermissions.basic);
    

提交回复
热议问题