[英]assigning string to a property of string type C#
I can better explain my problem by code 我可以通过代码更好地解释我的问题
here it is 这里是
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)
Here I need to set my property (data.lastname of string type) to a string actual value. 在这里,我需要将属性(字符串类型的data.lastname)设置为字符串实际值。 But how?
但是如何?
You need to move your 你需要移动你的
data.lastName = actual;
to after your else loop, if im reading your logic correct. 到您的else循环之后,如果即时通讯读取了正确的逻辑。
You have first assigned empty string property: 您首先分配了空字符串属性:
var actual = "";
data.lastName = actual;
and then update the value of actual, but the property still has "" as it's value You should just move 然后更新实际值,但该属性仍然具有“”作为其值,您应该移动
data.lastName = actual;
to the end of the code: 到代码末尾:
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.