我想要创建一个通知类或结构
我想用这样的东西:
//发送新通知
Notification newnotification = new Notification();
newnotification.Type = NotificationType.FriendRequest;
newnotification.Send("parm1", "parm2");我现在的试训班:
public class Notification
{
public struct NotificationType
{
// i dont know what to put here to add notification types
}
public NotificationType Type{ //dont know how to store the type here too }
public void Send(string Parm1, string Parm2)
{
// i put a code here to send to database
}
}发布于 2014-03-12 14:05:55
你需要一个enum
public enum NotificationType
{
FriendRequest,
OtherRequest,
...
}然后,您可以将它用作属性的类型:
public NotificationType Type
{
get;
set;
}你可以这样使用这个成员:
Notification n = new Notification();
n.Type = NotificationType.FriendRequest;如果要将属性值保存在数据库中,可以添加如下内容,使其易于从/转换到int:
public enum NotificationType : int
{
FriendRequest = 0,
OtherRequest = 1,
...
}然后,您可以像这样更容易地进行转换:
int valueInDB = (int)n.Type; // Will be 0 for "FriendRequest"从数据库获取值时,另一种方法是:
n.Type = (NotificationType)valueInDB;发布于 2014-03-12 14:05:19
只需创建自己的enum即可。
public enum NotificationType
{
FriendRequest,
OtherRequest
}用法:
public class MyClass
{
public NotificationType Type;
}
var myClass = new MyClass();
myClass.Type = NotificationType.FriendRequest;https://stackoverflow.com/questions/22353967
复制相似问题