Error : Wrong number of indexes '2' inside [], expected '1' Compilation failed in C# 2-D array


Hi, I am trying to run the below C# code for martix, but getting error

Wrong number of indexes `2' inside [], expected `1' Compilation failed: 1 error(s), 0 warnings

here is my current

using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
class Solution {
 static int formingMagicSquare(int[][] s) {
  int[] rowSum = new int[s.GetLength(0)], colSum = new int[s.GetLength(1)];
  int sum = 0;
  int magiconst = 15;
  int cons = 0;
  for (int r = 0; r < s.GetLength(0); r++) {
   for (int c = 0; c < s.GetLength(1); c++) {
    rowSum[r] += s[r, c];
   }
   sum += Math.Abs(rowSum[r] - magiconst);
  }
  return sum;
 }
 static void Main(string[] args) {
  TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
  int[][] s = new int[3][];
  for (int i = 0; i < 3; i++) {
   s[i] = Array.ConvertAll(Console.ReadLine().Split(' '), sTemp => Convert.ToInt32(sTemp));
  }
  int result = formingMagicSquare(s);
  textWriter.WriteLine(result);
  textWriter.Flush();
  textWriter.Close();
 }
}

How to resolve this error? Thanks


Asked by:- LuneAgile
0
: 5732 At:- 7/14/2018 4:31:02 PM
C# multi-dimensional array







1 Answers
profileImage Answered by:- LuneAgile

Hi, all sorry I just made a mistake on my code, should   rowSum[r] += s[r, c];    transformed to  rowSum[r] += s[r] [c];
Thanks

1
At:- 7/15/2018 10:01:27 PM
Thanks for commenting back here about this. 0
By : vikas_jk - at :- 7/16/2018 1:16:38 PM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use