如何仅使用一种方法返回多个值 [英] how to return multiple values using only one method

查看:64
本文介绍了如何仅使用一种方法返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个文本框............在一个文本框中我输入值1000

并在其TextBox1_TextChanged上我想计算值(1000 + 10%of1000) on textbox2



和(1000 + 20%of 1000)textbox3并且只想使用一种方法 cal 并希望此方法在一个班级



和TextBox1_TextChanged:通过类对象方法 cal 应该被调用

这是可能的

请告诉

关于

i have three textboxes............in one textbox i input value 1000
and on its TextBox1_TextChanged i want to calculate values (1000+10%of1000) on textbox2

and (1000+20%of1000) on textbox3 and want to use only one method cal and want this method to be in a class

and in TextBox1_TextChanged: through class object method cal should be invoked
is this possible
pls tell
regards

推荐答案

要返回多个值,您可以使用ref或out关键字作为参数,例如:



你可以使用/ out

To return multiple values you can use either ref or out keyword as your arguments eg:

you can use /out
void ReturnMultiple(out string value1,out int value2,out flow value3)
{
   value1 = "value1";
   value2 = 0;
   value3 = 100.0f;
}



or

void ReturnMultiple(ref string value1,ref int value2,ref flow value3)
{
   value1 = "value1";
   value2 = 0;
   value3 = 100.0f;
};





了解更多关于''ref''和''out''关键词在这里

参考之间有什么区别在C#中输出关键词? [ ^ ]


Protected Void TextBox1_TextChanged(Sender s,Object e)
{

Str= CalculateBoth(val1,val2,val3);
string[] words = str.Split(',');
Txt1.Text=words[0];
Txt2.Text=words[1];
} 
static void CalculateBoth(int a,int b,int c)
{
int d=a + b % c;
int e=a + (b+10) % c;
string str= convert.toString(d) + "," + convert.toString(e);
return str;   
}





这是例如你可以这样做......



This Is For Example You can Do Like This...


这篇关于如何仅使用一种方法返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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