gpt4 book ai didi

c# - C# 中的静态抽象方法

转载 作者:太空宇宙 更新时间:2023-11-03 19:35:38 24 4
gpt4 key购买 nike

我知道静态抽象方法是同义反复,但我该怎么做:

基类,抽象类:

abstract class QTimerDatabaseObject {

public static abstract QTimerDatabaseObject createFromQTimer(DataRow QTimerRow);
public abstract void saveRow();
}

示例实现(在扩展 QTimerDatabaseObject 的用户类中):

    public static override QTimerDatabaseObject createFromQTimer(DataRow QTimerRow) {
int ID = (int)QTimerRow["id"];

string Username = QTimerRow["username"].ToString();
string Init = (QTimerRow["init"] ?? "").ToString();
string FirstName = (QTimerRow["FirstName"] ?? "").ToString();
string MiddleInitial = (QTimerRow["Midinit"] ?? "").ToString();
string LastName = (QTimerRow["Lastname"] ?? "").ToString();
string Salutation = (QTimerRow["salutation"] ?? "").ToString();

int RefNum = (int)(QTimerRow["refnum"] ?? -1);
int Timestamp = (int)(QTimerRow["timestamp"] ?? -1);
int DelCount = (int)(QTimerRow["delcount"] ?? 0);

bool IsHidden = (bool)(QTimerRow["hidden"] ?? false);

return new User(ID, Username, Init, FirstName, MiddleInitial, LastName, Salutation, RefNum, Timestamp, DelCount, IsHidden);
}

我怎样才能做这样的事情?

最佳答案

我想你想要的是 Factory Design Pattern .

关于c# - C# 中的静态抽象方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1772537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com