我有一个我正在下面使用的课程.我正在将此类用于我的Windows应用程序.但是,当我从我的应用程序ReadInConfig()调用该方法时,它成功读取并填充数据表,并分配_sip_ip地址.
在我的Windows应用程序中,我有以下内容.但是,它没有给我分配它的sip_ip.
ConfigSIP readIn = new ConfigSIP();
readIn.ReadInConfig();
string sip_ip = readIn.sip_ip(); // Get nothing here.
Run Code Online (Sandbox Code Playgroud)
我在想,因为数据表分配的_sip_ip是一个不同的对象,而不是执行此操作readIn.sip_ip();
有什么办法可以解决这个问题吗?
非常感谢,
public class ConfigSIP
{
private string _sip_ip;
// Fill the data table and assign the sip ip.
public void ReadInConfig()
{
DataTable dt = new DataTable("Admin");
dt.ReadXmlSchema(@"C:\Config.xml");
dt.ReadXml(@"C:\Config.xml");
_sip_ip = dt.Rows[0]["Sip_ip"].ToString();
}
// Return the sip ip address.
public string sip_ip()
{
return _sip_ip;
}
}
Run Code Online (Sandbox Code Playgroud)
你忘了打电话给ReadInConfig:
ConfigSIP readIn = new ConfigSIP();
readIn.ReadInConfig();
string sip_ip = readIn.sip_ip();
Run Code Online (Sandbox Code Playgroud)