'error CS1061: Type `System.Collections.Generic.List<System.Collections.Generic.List<int>>' does'nt contain a def for `GetLength' and no extension mthd
im coding in C# and getting
does not contain a definition for
GetLength' and no extension methodGetLength' of type
in HACKERRANK...the same code is executable([and giving correct answer][1]) on Visual Studio 2019 and not working on HackerRank Compiler.I have this problem several time while working with arrays on HackerRank & I used Count ...But in 2D Array the Count didn't work.
public static int diagonalDifference(List<List<int>> arr)
{
int sumRight=0;
int sumLeft=0;
//sum of left Diagonal
for(int i=0;i<arr.GetLength(0);i++)
{
for(int j=i;j<arr.GetLength(1);j++)
{
sumRight = sumRight + arr[i, j];
break;
}
}
//Console.WriteLine(sumRight);
//Sum of Left diagonal
int p = -1;
for (int i=arr.GetLength(1)-1;i>=0;i--)
{
p = p + 1;
for(int j=p;j<arr.GetLength(0);j++)
{
sumLeft = sumLeft + arr[j, i];
break;
}
}
//Console.WriteLine(sumLeft);
//calculate diagonal difference
int absolute = sumRight - sumLeft;
int abpos = Math.Abs(absolute);
return abpos;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
