gpt4 book ai didi

c# - 为类设置返回值

转载 作者:行者123 更新时间:2023-11-30 22:15:39 24 4
gpt4 key购买 nike

我有以下方法,我正在尝试从名为 ApptDateTime 的列中获取数据并将其设置为公共(public)类,以便我可以将值传递给另一个方法。

这就是我试图在公共(public)类中设置的值:

public class ApptData
{
public DateTime _currentAppointment { get; set; }
}

我选择值 _currentAppointment,我希望能够从 public class ApptData 调用它,然后将其传递到方法中。

EX: history.LoadHistory(ApptData appointment, daysOfHistory);

    private void dgvPendingSB_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
DataRowView row = (DataRowView)e.AddedItems[0];

int accNum = -1;
int resourceId = Convert.ToInt32(row["ResourceId"]);
int locationId = Convert.ToInt32(row["LocationId"]);
int patientId = Convert.ToInt32(row["PatientId"]);
_currentAppointment = Convert.ToDateTime(row["ApptDate"]);
m_objPatient = Convert.ToInt32(row["PatientId"]);
_stringPatientName = row["PatientName"].ToString();
// ...
}
}

最佳答案

如果您尝试将ApptData新实例 传递到LoadHistory 中,其中的值来自您的DataRowView 设置,你会想要这样的东西:

history.LoadHistory(new ApptData()
{
_currentAppointment = Convert.ToDateTime(row["ApptDate"])
}, daysOfHistory);

此外,我强烈建议您不要public 属性、字段或方法的开头使用下划线。只是很奇怪

关于c# - 为类设置返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17866716/

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