Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing jagged array values in C#

Status
Not open for further replies.

jasonsalas

IS-IT--Management
Jun 20, 2001
480
GU
Hi everyone,

I'm developing a custom control in which I sift through the contents of an XML document and populate a jagged array (actually, it's an array with a variable number of elements, but always has 2 values for each element).

I'm trying to loop through the array, but I keep getting the error message: "Cannot apply indexing with [] to an expression of type 'System.Array' when trying to access the values with my code. It looks cut-and-dry (or so I thought), but it won't work.

Here's my code:
private Array GetFiles(string fileProperty)
{
FileStream fs = new FileStream(fileProperty,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
DataSet ds = new DataSet();
ds.ReadXml(sr);
fs.Close();

DataTable table = ds.Tables[0];
DataRow[] rows = table.Select();

// POPULATE THE ARRAY HERE
string[][] arrSubmissions = new string[rows.Length][];
for(int i=0;i<rows.Length;i++)
{
arrSubmissions = new string[2] { rows[&quot;link&quot;].ToString(),rows[&quot;title&quot;].ToString() };
}

return arrSubmissions;
}

protected override void Render(HtmlTextWriter writer)
{
// call the private helper method
Array sl = GetFiles(DataFile);
for(int i=0;i<sl.Length;i++)
{
for(int j=0;j<sl.Length;j++)
{
// THIS LINE CAUSES THE ERROR
writer.Write(&quot;{0},sl[j]);
}
}
}

Any ideas?
 
Updated code:

// THIS LINE CAUSES THE ERROR
writer.Write(&quot;{0}&quot;,sl[j]);
 
Updated code:

// THIS LINE CAUSES THE ERROR
writer.Write(&quot;{0}&quot;,sl[j]);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top