获取/设置和sevral值 [英] get / set and sevral values

查看:109
本文介绍了获取/设置和sevral值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用获取和设置

其中值是说三个整数。

如果是的话,是否有示例代码?


Adrian。

Is it possible to use "get" and "set"
where "value" is say three ints.
If so, is there sample code anywhere?

Adrian.

推荐答案

不作为单一财产;

你可以:

a:写一个3out的Get方法params和一个带有3

参数的Set方法

b:使用数组

c:用3个值创建一个结构


Marc

Not as a single property;
you could:
a: Write a Get method that has 3 "out" params, and a Set method with 3
params
b: use an array
c: create a struct with the 3 values

Marc


谢谢Marc。
Thank you Marc.


你能否告诉我我如何修改代码以便它可以工作?


使用System;

使用System.Collections;


命名空间trial_two

{


公共类Class1

{

static void Main(string [ ] args)

{

HashArray ha = new HashArray();

显示d =新显示(22,33);

ha.hash = d; //错误在这里********

}


公共类HashArray

{

public Hashtable hash = new Hashtable();

显示这个[int loc]

{

get

{

返回哈希[loc]显示;

}

设置

{

hash.Add(loc,value);

}

}

}

}


公共类显示

{

int arg1;

int arg2;


public Display(int arg1,int arg2)

{

this.arg1 = arg1;

this.arg2 = arg2;

}

}

}
Could you please tell me how to modify the code so it will work?

using System;
using System.Collections;

namespace trial_two
{

public class Class1
{
static void Main(string[] args)
{
HashArray ha = new HashArray();
Display d = new Display(22,33);
ha.hash = d; // error here ********
}

public class HashArray
{
public Hashtable hash = new Hashtable();
Display this[int loc]
{
get
{
return hash[loc] as Display;
}
set
{
hash.Add(loc, value);
}
}
}
}

public class Display
{
int arg1;
int arg2;

public Display(int arg1, int arg2)
{
this.arg1 = arg1;
this.arg2 = arg2;
}
}
}


这篇关于获取/设置和sevral值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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