[英]assigning string to a property of string type C#
我可以通过代码更好地解释我的问题
这里是
strind abc="12345678<9";
row1ViewModel data = new row1ViewModel();
data.identityType = abc[0].ToString();
data.passportType = abc[1].ToString();
data.issuingOrg = abc.Substring(2, 3);
var actual = "";
data.lastName = actual;
//data.lastName = actual;
if (abc[5] == '<')
{
actual = "Not specified";
}
else
{
string tempq = abc.Substring(5);
int index = tempq.IndexOf('<');
actual = abc.Substring(5, index);
}
//data.GetType().GetProperty(data.lastName).GetValue(actual,null)
在这里,我需要将属性(字符串类型的data.lastname)设置为字符串实际值。 但是如何?
你需要移动你的
data.lastName = actual;
到您的else循环之后,如果即时通讯读取了正确的逻辑。
您首先分配了空字符串属性:
var actual = "";
data.lastName = actual;
然后更新实际值,但该属性仍然具有“”作为其值,您应该移动
data.lastName = actual;
到代码末尾:
strind abc="12345678<9";
row1ViewModel data = new row1ViewModel();
data.identityType = abc[0].ToString();
data.passportType = abc[1].ToString();
data.issuingOrg = abc.Substring(2, 3);
var actual = "";
//data.lastName = actual;
if (abc[5] == '<')
{
actual = "Not specified";
}
else
{
string tempq = abc.Substring(5);
int index = tempq.IndexOf('<');
actual = abc.Substring(5, index);
}
//data.GetType().GetProperty(data.lastName).GetValue(actual,null)`
data.lastName = actual;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.