public void show(string s)
{
public char[][]pHone = new char[8][]{new char[3]{ 'a','b','c'},new char[3]{'d','e','f'},new char[3]{'g','h','i'},new char[3]{'j','k','l'},new char[3]{'m','n','o'},new char[4]{'p','q','r','s'},new char[3]{'t','u','v'},new char[4]{'w','x','y','z'}};
Console.Write("{0}",pHone[0]);//想通过此条语句输出a,b,c
}
但输出了
System.Char[]
这英文怎么出现的?
为什么pHone[0]不会输出a,b,c
交错数组的每个元素是一个数组。
C#中,如果一个对象没有重写ToString方法,默认输出的是类型名。
比如
class A {}
main里面
Console.WriteLine(new A());
输出就是A
你要输出a,b,c可以用
using System;
using System.Linq;
public class Test
{
public static char[][]pHone = new char[8][]{new char[3]{ 'a','b','c'},new char[3]{'d','e','f'},new char[3]{'g','h','i'},new char[3]{'j','k','l'},new char[3]{'m','n','o'},new char[4]{'p','q','r','s'},new char[3]{'t','u','v'},new char[4]{'w','x','y','z'}};
public static void Main()
{
// your code goes here
Console.Write("{0}",string.Join(",", pHone[0].Select(x => x.ToString())));
}
}
a,b,c
在线验证网址:https://ideone.com/mwNEXm