6 Replies - 627 Views - Last Post: 01 March 2013 - 05:10 AM Rate Topic: -----

#1 Thobisa90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-December 11

Returning an Array In C#

Posted 28 February 2013 - 03:32 AM

Hi good people once again,

I just stared C#, now i have a problem
with returning an array in a function
here is my Code:
public string[][] PopulationAndFittness(string ChildP,int Row,int column)
          {
              string [,]P= new string[100000,2];

              P[ Row,column] = ChildP;
              int fit = fitness(ChildP);
              P[Row, column] = Convert.ToString(fit);

              return [u]P;[/u]

          }

it says "Error 1 Cannot implicitly convert type 'string[*,*]' to 'string[][]"
look forward to your suggestions

This post has been edited by tlhIn`toq: 28 February 2013 - 08:19 AM
Reason for edit:: [code]Code tags aren't rocket science people[/code]


Is This A Good Question/Topic? 0
  • +

Replies To: Returning an Array In C#

#2 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: Returning an Array In C#

Posted 28 February 2013 - 03:38 AM

your return type in no good
Was This Post Helpful? 0
  • +
  • -

#3 MrShoes  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 314
  • View blog
  • Posts: 490
  • Joined: 13-June 12

Re: Returning an Array In C#

Posted 28 February 2013 - 03:38 AM

It's telling you the problem. Without showing you (in the interests of helping you learn), take a look at the difference between the type of P and the type the method returns.
Was This Post Helpful? 2
  • +
  • -

#4 Thobisa90  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 13-December 11

Re: Returning an Array In C#

Posted 01 March 2013 - 02:47 AM

Thanks Guys

I have found the solution!
i should have use string [,] instead of string[][]

THANKS!
Was This Post Helpful? 0
  • +
  • -

#5 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: Returning an Array In C#

Posted 01 March 2013 - 04:34 AM

string [][] is used in JAVA and string [,] is used in C#
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: Returning an Array In C#

Posted 01 March 2013 - 04:48 AM

View PostMichael26, on 01 March 2013 - 12:34 PM, said:

string [][] is used in JAVA and string [,] is used in C#


string[][] is a perfectly legal type in C# as well - it's just not the same type as string[,].
Was This Post Helpful? 0
  • +
  • -

#7 Michael26  Icon User is offline

  • DIC-head, major DIC-head
  • member icon

Reputation: 362
  • View blog
  • Posts: 1,539
  • Joined: 08-April 09

Re: Returning an Array In C#

Posted 01 March 2013 - 05:10 AM

Didn't know that thanks, and offtopic(and no offence ;) ) if you're responding to someone right above you, you don't need to quote them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1