简体   繁体   中英

How to pass Enum to function and how to evaluate enum in if statement c#

suppose i have class which has one enum. so when some one will call class function then they will send a enum value to function and from function we like to use if statement to check what value has been sent.

public class BBALogger
{
enum MsgType
{
    Error ,
    Info 
}

public void WriteToLog(String inLogMessage, Enum msgtype)
{
     if(msgtype==MsgType.Error)
     {

     }
     else if(msgtype==MsgType.info)
     {

     }
}
}

calling function like this way

class BBALogger x = new BBALogger()
x.WriteToLog("Hello",MsgType.Error);

i am getting error. where i am making the mistake.

You can simply use MsgType instead of Enum

public void WriteToLog(String inLogMessage, MsgType msgtype)
{
     if(msgtype==MsgType.Error)
     {

     }
     else if(msgtype==MsgType.info)
     {

     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM