C#中方法的多个输出数据类型 [英] multiple output data type for method in C#
本文介绍了C#中方法的多个输出数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的朋友:
我想有一个具有两个输入和一个 两个不同的输出 的方法.
例如:
Dear friends:
I want to have a method that has two input and two different output.
For example:
private int , byte Nameofmethod (string s , int i)
{
}
我该怎么办?
Yours
How should I do that?
Yours
推荐答案
通常,我认为更好的方法是返回一个包含所需所有输出的对象.不确定,这可能是您正在寻找的更好的解决方案.
Generally what I consider a better way is to return an object that contains all of the outputs you need. That may be a better solution for what you are looking for, cannot be sure.
private struct ReturnedObject
{
public ReturnedObject(string variable1, string variable2)
{
Variable1 = variable1;
Variable2 = variable2;
}
public string Variable1;
public string Variable2;
}
private ReturnedObject SomeMethod ()
{
return new ReturnedObject("first value", "second value");
}
有一些例外,但是C#是一种面向对象的语言,应该使用对象.我也更喜欢对象作为参数,否则某些调用会变得很长.对此的理解就是我正在做类似TryParse
There are exceptions, but C# is an object oriented language and should be using objects. I also prefer objects as arguments, otherwise some calls can become very long. The exeception to this would be where I am doing something like TryParse
的事情,使用带有out关键字的参数:
Use parameters with the out keyword:
private void MyMethod(string s, int i, out int intResult, out byte byteResult)
这篇关于C#中方法的多个输出数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文