是否有可能与不同类型的返回多个值? [英] Is it possible to return multiple values with different types ?
本文介绍了是否有可能与不同类型的返回多个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Javascript中我可以返回一个对象的函数:
功能的人(){
返回{名称:李四,年龄:20,isMarried:假};
}
的console.log(姓名:+人()名+时代:+人()年龄+已婚:+人() 。已经结婚);
输出:
> 姓名:李四年龄:20结婚:假
我想知道是否有可能做在C#这样的事情?我一直在阅读有关代表,词典和匿名方法,但我仍然没有关于这条线索。
解决方案
静态无效的主要(字串[] args)
{
动态p =人();
Console.WriteLine(名称:{0},年龄:{1},已婚:{2},p.name,p.age,p.isMarried);
}
静态动态的人()
{
返回新{NAME =李四,年龄= 20,isMarried = FALSE};
}
更多信息
In Javascript I can make a function that returns an object:
function person() {
return { name: "John Doe", age: 20, isMarried: false };
}
console.log("Name: "+ person().name +". Age: "+ person().age +". Is married: "+ person().isMarried);
OUTPUT:
> "Name: John Doe. Age: 20. Is Married: false"
I was wondering if it's possible to do something like this in C#? I've been reading about delegates, dictionaries and anonymous methods but I still have no clue about this.
解决方案
static void Main(string[] args)
{
dynamic p = person();
Console.WriteLine("Name: {0}, Age: {1}, Is married: {2}", p.name, p.age, p.isMarried);
}
static dynamic person()
{
return new { name = "John Doe", age = 20, isMarried = false };
}
More info about the dynamic
keyword
这篇关于是否有可能与不同类型的返回多个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文