使我们自己的名单,LT;字符串,字符串,字符串> [英] Make our own List<string, string, string>

查看:137
本文介绍了使我们自己的名单,LT;字符串,字符串,字符串>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以做我们自己的列表<字符串,字符串,字符串> 在C#.NET?我需要有3个不同的字符串作为列表中的一个元素的列表。

Can we make our own List<string, string, string> in C#.NET? I need to make a list having 3 different strings as a single element in the list.

推荐答案

您也可以创建自己的类名为列表有三个泛型类型参数。我的强烈的阻止你这样做虽然。它会混淆的挫折感使用你的代码的任何人

You can certainly create your own class called List with three generic type parameters. I would strongly discourage you from doing so though. It would confuse the heck out of anyone using your code.

相反,或者的使用列表与LT元组LT;字符串,字符串,字符串>> (如果你使用.NET 4,反正)或(最好)创建自己的类来封装以有意义的方式这三个字符串,然后用列表< YourNewClass>

Instead, either use List<Tuple<string, string, string>> (if you're using .NET 4, anyway) or (preferrably) create your own class to encapsulate those three strings in a meaningful way, then use List<YourNewClass>.

创建自己的类将使它当你写和读代码更清晰 - 通过为名称。所涉及的三个不同的琴弦,每个人都知道他们是什么意思意思。你也可以给更多的行为的类,当你需要。

Creating your own class will make it much clearer when you're writing and reading the code - by giving names to the three different strings involved, everyone will know what they're meant to mean. You can also give more behaviour to the class as and when you need to.

这篇关于使我们自己的名单,LT;字符串,字符串,字符串&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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