c# - How do I require an enum as a strong typed parameter? -
i may going entirely wrong open , suggestions. trying require statustype
parameter in this:
response(statustype.submit, message);
to limited set of types return constant string value. far have come solution:
public class response { private statustype _status; response(statustype status, string message) { _status = status; } public string status { { return enum.getname(typeof(statustype), _status); } } } public enum statustype { fail, success, response, confirm }
but realize enum parameter weak-typed , allow me enter string value instead. can me? have feeling enum not solution i'm not sure of way.
based on comments, getting error when using class vb project.
when option strict
turned off, vb try "helpfully" convert objects between "compatible" types. hides mistakes , causes hard track down errors. recommend turning 'option strict` on when developing in visual basic; write better code.
you can turn option strict on entire project compile
tab in project properties (recommended way), or individual files adding option strict on
top of file outside of class definitions.
Comments
Post a Comment