Thursday, May 26, 2016

System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Learn
{
class Arrays
{
static void Main(String[] args)
{
//Single Dimenstional Array
int[] numbers=new int[4];

//Two Dimenstional Array
string[,] twoNum=new string[4,5];

//Arrays of Arrays (Jagged)

byte[][] score = new byte[5][];

for(int i=0;i<score.length;i++)
{
score[i]=new byte[i+3];
}

for(int i=0;i<score.length;i++)
{
Console.WriteLine("Row Number{0} and its value is{1}",i,score[i].length);
}
Console.ReadLine();

}
}
}
Note: Red Color Indicates Cause Of Error.

After Completing Errors are :



cs(22,24): error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)


 cs(27,24): error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

 cs(29,71):error CS1061: 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

Conclusion is : Change length to Length.

Output of Programming is :

C:\Users\Vijay\Documents\Visual Studio 2012\Projects\Learn>Arrays
Row Number 0 and its value is 3
Row Number 1 and its value is 4
Row Number 2 and its value is 5
Row Number 3 and its value is 6
Row Number 4 and its value is 7

After Execution Programming is

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Learn
{
class Arrays
{
static void Main(String[] args)
{
//Single Dimenstional Array
int[] numbers=new int[4];

//Two Dimenstional Array
string[,] twoNum=new string[4,5];

//Arrays of Arrays (Jagged)

byte[][] score = new byte[5][];

for(int i=0;i<score.Length;i++)
{
score[i]=new byte[i+3];
}

for(int i=0;i<score.Length;i++)
{
Console.WriteLine("Row Number {0} and its value is {1}", i , score[i].Length );
}
Console.ReadLine();

}
}
}


No comments:

Post a Comment