想获取二维数组中的某一行中的前n个元素,试了好几种方法,一直不对,怎么破?
double[,] s = { { 0,1,1,0 }, { 1,0,1,0 }, { 1,1,0,1 } };比如说要获得上述数组的第二行的前两个元素,该怎么获取?如果s大小变为100×100呢?如何获得某一行的前n个元素?求大神赐教!!!(最好不用循环)
2016-11-04 11:13
2016-11-04 16:16
程序代码:using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace array
{
class Program
{
static void Main(string[] args)
{
double[,] s = { { 0, 1, 1, 0 }, { 1, 0, 1, 0 }, { 1, 1, 0, 1 } };
Console.Write(s[1, 0]); //第二行第一个元素
Console.WriteLine(s[1, 1]); //第二行第二个元素
for (int i = 0; i < 4; i++)
{
Console.Write(s[2, i]); //第三行的元素
}
Console.ReadKey();
}
}
}
2016-11-05 09:39