类类型到字符串类型 [英] Class type to string type

查看:73
本文介绍了类类型到字符串类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public   class 记录
{

public 列表< Field> FieldS = new 列表< Field>();
public string getting_StructureField( string structurefield_identifier)
{
Field s = new Field();
s.StructureField_Identifier = structurefield_identifier;

FieldS.Add(s);

return structurefield_identifier;

}
public string gettingByteoffset( string byte_offset)
{
Field b = new Field();
b.ByteOffset = byte_offset;
Field.Add(b);
return byte_offset;
}
}





----------------- -------------------------------------------------- -

记录记录=新记录(); 
for(int u = 1; u < i; u ++)

{

doc.SelectSingleNode(SVD_Schema / RECORDS / Record [@Indntifier =' + Command_No +' ] / Fields / StructureField [ + u + ] / @ Identifier)。InnerText = record.FieldS [u-1];

}

}





我用这个for循环,它显示不能隐式地将类型字段转换为字符串。

如何转换它?

解决方案

这里:< a href =http://msdn.microsoft.com/en-us/library/system.object.tostring%28v=vs.110%29.aspx> http://msdn.microsoft.com/en-us /library/system.object.tostring%28v=vs.110%29.aspx [ ^ ]。



我不确定你真的需要在你的情况下这样做,但很明显,你首先需要学习基础知识。除非您定义类型,否则类型永远不会转换为另一个。有类型转换,转换操作符,方法和属性返回特定类型的对象,等等。



-SA


 record.FieldS [u-1]; 





在此,记录是一个类,'Fields'是用于记录的列表类型数据成员。

这里'Fields'是一个'Field'类型对象列表。您正在尝试使用'record.FieldS [u-1]'表达式分配字符串值但是'[u-1]'是一个'字段'类型的对象而不是任何单个值,因此您将能够获得其值字符串。


public class Record
   {

public List<Field> FieldS = new List<Field>();
public string getting_StructureField(string structurefield_identifier)
       {
           Field s = new Field();
           s.StructureField_Identifier = structurefield_identifier;

           FieldS.Add(s);

           return structurefield_identifier;

       }
 public string gettingByteoffset(string byte_offset)
        {
            Field b = new Field();
            b.ByteOffset = byte_offset;
            Field.Add(b);
            return byte_offset;
        }
}



--------------------------------------------------------------------

Record record =new Record();
for(int u=1;u<i;u++)

            {

              doc.SelectSingleNode("SVD_Schema/RECORDS/Record[@Identifier='" + Command_No + "' ]/Fields/StructureField[ " + u + "]/@Identifier").InnerText =record.FieldS[u-1];

            }

           }



When I use this for loop, it is showing cannot implicitly convert type Field to string.
How to Convert that?

解决方案

Here: http://msdn.microsoft.com/en-us/library/system.object.tostring%28v=vs.110%29.aspx[^].

I'm not sure you really need to do it in your case, but it's apparent that you first need to learn the very basics. Types are never "converted" one to another unless you define it. There are type casts, cast operators, methods and properties returning objects of certain type, and so on.

—SA


record.FieldS[u-1];



In this, record is an class, 'Fields' is list type data member for record.
Here 'Fields' is an list 'Field' type object. You are trying to assign string value with 'record.FieldS[u-1]' expression But'[u-1]' is an 'Field' type of object not any single value so that you will be able to get its value as string.


这篇关于类类型到字符串类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆