好吧..我有一个非常尴尬的问题,我相信是与C#如何处理值类型与引用类型相关,但我不知道究竟是什么错误。C#字符串去结构
public partial class LogicSimulationViewerForm : Form
{
private Dictionary<string, PointStruct> pointValues;
private void SearchPoint(string code)
{
ReadDefaultPointValuesResponse result = ddcdao.ReadDefaultPoint(points);
pointValues = new Dictionary<string, PointStruct>();
for (int j = 0; j < result.pointidentifier.Length; j++)
{
if (!pointValues.ContainsKey(result.pointidentifier[j]))
{
PointStruct ps = new PointStruct();
ps.name = "Random String";
ps.pointidentifier = result.pointidentifier[j];
ps.outofservice = result.outofservice[j];
pointValues.Add(result.pointidentifier[j], ps);
...
pointValues存储为类中的私有字段。现在,在同一类,但不同的功能,如果我尝试做到以下几点:
PointStruct ps = pointValues[s];
MessageBox.Show(ps.name);
MessageBox.Show(ps.pointidentifier);
MessageBox.Show(ps.outofservice);
的ps.pointidentifier和ps.outofservice显示正常,但ps.name始终返回空不管我做。我该如何解决这个问题?
编辑:根据要求,我加入更多的代码来进一步说明这个问题:
public struct PointStruct
{
public string pointidentifier;
public string affect;
public string outofservice;
public string priorityarray;
public string pointtype;
public string alarmstate;
public string correctvalue;
public string presentvalue;
public string name;
public string test;
}
如果您可以显示一个显示问题的简短但完整的程序,最好是一个控制台应用程序,这将非常有帮助。噢,看起来你的设计良好的结构中有太多的字段。任何你没有成为课堂的理由? – 2012-07-06 12:31:01
也提供'PointStruct'结构。 – yogi 2012-07-06 12:32:17
@roken我不打电话给pointValues.Add其他地方。 – l46kok 2012-07-06 12:32:22