本文介绍了访问没有对象名称和属性名称的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常如果我需要Accces类属性,比我用来编写objectname.properties名称(tempRecord),但是怎么来这里工作没有写objectname.properties名称
class TempRecord
{
private float [] temps = new float [ 10 ] { 56 .2F, 56 .7F, 56 .5F, 56 .9F, 58 .8F,
61 .3F, 65 .9F , 62 .1F, 59 .2F, 57 .5F};
private int vps;
public float this [ int index]
{
get
{
return temps [index];
}
set
{
temps [index] = 值;
}
}
public int mava
{
set
{
vps = value ;
}
获取
{
返回 vps + VPS;
}
}
}
class MainClass
{
static void Main()
{
TempRecord tempRecord = new TempRecord();
tempRecord.mava = 4 ;
// 通常如果我需要Accces类属性,比我用来写objectname.properties名称(tempRecord) ,
// 但是如何在这里工作没有编写objectname.properties名称
tempRecord [ 3 ] = 58 .3F; // 这里没有编写objectname.properties名称
tempRecord [ 5 ] = 60 .1F; // 此处无编写objectname.properties名称
for ( int i = 0 ; i < 10 ; i ++)
{
System.Console.WriteLine( 元素#{0} = {1},i,tempRecord [i]);
}
System.Console.WriteLine( 按任意键退出。);
System.Console.ReadKey();
}
}
解决方案
Usually If I Need Accces Class properties , Than I Used To Write objectname.properties name(tempRecord) , But How Come Here It Work's Without Writing objectname.properties name
class TempRecord { private float[] temps = new float[10] { 56.2F, 56.7F, 56.5F, 56.9F, 58.8F, 61.3F, 65.9F, 62.1F, 59.2F, 57.5F }; private int vps; public float this[int index] { get { return temps[index]; } set { temps[index] = value; } } public int mava { set { vps = value; } get { return vps + vps; } } } class MainClass { static void Main() { TempRecord tempRecord = new TempRecord(); tempRecord.mava = 4; // Usually If I Need Accces Class properties , Than I Used To Write objectname.properties name(tempRecord) , //But How Come Here It Work's Without Writing objectname.properties name tempRecord[3] = 58.3F; // Here Without Writing objectname.properties name tempRecord[5] = 60.1F; // here Without Writing objectname.properties name for (int i = 0; i < 10; i++) { System.Console.WriteLine("Element #{0} = {1}", i, tempRecord[i]); } System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); } }
解决方案
这篇关于访问没有对象名称和属性名称的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!