array.Rank doesn't seem to work with string arrays ????

J

Jeff Fischman

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] strings = {"a","bc","def",null};
Console.WriteLine("strings.Rank = {0}", strings.Rank);
}
}
}


this prints out strings.rank = 1 (instead of 4)

let me know if I am doing something wrong
 
R

Rudy Velthuis

Jeff said:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] strings = {"a","bc","def",null};
Console.WriteLine("strings.Rank = {0}", strings.Rank);
}
}
}


this prints out strings.rank = 1 (instead of 4)

1 is perfectly correct. This is a one-dimensional array, so Rank
returns 1. Are you looking for the length of the array, perhaps? Then
it should return 5, not 4.
 
R

Rudy Velthuis

Jeff said:
let me know if I am doing something wrong

ms-help://MS.NETFramework.v20.en/cpref2/html/P_System_Array_Rank.htm

<<
Property Value
The rank (number of dimensions) of the Array.
Since this array is one-dimensional, 1 is correct. I guess you want
Array.Length:

ms-help://MS.NETFramework.v20.en/cpref2/html/P_System_Array_Length.htm



--
Rudy Velthuis http://rvelthuis.de

"Devlin's First Law - Buyer beware: in the hands of a charlatan,
mathematics can be used to make a vacuous argument look
impressive.
Devlin's Second Law - So can PowerPoint." -- Keith Devlin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top