如何创建的元组数组? [英] How to create an array of tuples?

查看:140
本文介绍了如何创建的元组数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,C#创建一个元组,我们使用的格式为:

I know that to create a tuple in C#, we use the format:

Tuple <int,int>from = new Tuple<int,int>(50,350);
Tuple <int,int>to = new Tuple<int,int>(50,650);



其中每个元组是一个坐标对。
我想创建一个阵列使用元组多个坐标对。有人能帮助我在这

where each tuple is a coordinate pair. I am trying to create an array of multiple coordinate pairs using tuples. Could someone help me out on this?

编辑:这是我到目前为止已经试过。我想它是只此阵列格式。

This is what I have tried so far. I want it to be in this array format only.

 Tuple<int, int>[] coords = new Tuple<int,int>({50,350},{50,650},{450,650});



编译器抱怨说有什么不对。请告诉我这是什么?

Compiler complains that there is something wrong.. Please tell me what it is?

推荐答案

您可以如下定义它:

Tuple<int, int>[] tuples =
{
    Tuple.Create(50, 350),
    Tuple.Create(50, 650),
    ...
};



不过,如果这是坐标值,我可能会使用点来代替:

Though if this is coordinate values, I'd probably use Point instead:

Point[] points =
{
    new Point(50, 350),
    new Point(50, 650),
    ...
};

这篇关于如何创建的元组数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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