定义一个字符串数组,提示用户输入"hello"将没一个字符当成一个元素输入字符数组,并将他们输出;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication14
{
    class Program
    {
        static void Main(string[] args)
        {
            int b;
            string[] a = new string[5];
            int i;
            for (i = 0; i < 5; i++)
            {
                b = Console.Read();
                //a[i] = char.Parse(b);                这里错了 应该怎么转换?
            }
            for (i = 0; i < 5; i++)
            {
                Console.Write("{0}", a[i]);
            }        }
    }
}

解决方案 »

  1.   

    char.Parse(b);                返回类型是字符串吗
      

  2.   

    char ch; 
    ch = (char) Console.Read(); string str; 
    str = Console.ReadLine(); 
      

  3.   

    a[i]是字符串类型,直接b.toString()呗
      

  4.   

         int b;
                string[] a = new string[5];
                int i;
                for (i = 0; i < 5; i++)
                {
                    b = (char)Console.Read();
                    a = 这里该怎么转换?
                    
                }
                for (i = 0; i < 5; i++)
                {
                    Console.Write("{0}", a[i]);
                }
      

  5.   

       using System;
    class Test
    {
        static void Main(string[] args)
        {
            string b;
            char[] c = new char[5];
            int i;
            b = args[0];
            for (i = 0; i < 5; i++)
            {
                c[i] = b[i];
                Console.Write("{0}", c[i]);
            }     }
    }
    F:\>Test hello
    hello
      

  6.   

       using System;
    class Test
    {
        static void Main(string[] args)
        {
            string b;
            char[] c = new char[5];
            int i;
            b = args[0];
            for (i = 0; i < 5; i++)
            {
                c[i] = b[i];
                Console.WriteLine("{0}", c[i]);
            }     }
    }
    F:\>Test Hello
    H
    e
    l
    l
    o
      

  7.   

    其实都没必要定义char[] c = new char[5];
       直接  Console.WriteLine("{0}", b[i]);就可以 
      

  8.   

    namespace ConsoleApplication14 

        class Program 
        { 
            static void Main(string[] args) 
            { 
                int b; 
                char[] a = new char[5]; 
                int i; 
                foreath (i = 0; i < 5; i++) 
                {                 b = Console.Read(); 
                    b.substring(i,1);
                    a[i] = char.Parse(b);                           } 
                for (i = 0; i < 5; i++) 
                {                 Console.Write("{0}", a[i]); 
                }         } 
        } 

      

  9.   


    第15行报错 b = args[0];
      

  10.   

     foreath (i = 0; i < 5; i++) 
    改 for(i = 0; i < 5; i++) 
      

  11.   

     foreath   foreach
      

  12.   


    而且你这个代码好像没有 输入啊?那怎么显示hello?莫非你的编译器不一样?
      

  13.   


    能帮忙讲下这个    b.substring(i,1);方法是怎么使用的么?
      

  14.   

    b.substring(i,j);
    截取b字符串,从b的i个下标开始截取,每行截取j个字符
      

  15.   

    你那个程序报错啊,for改过来了 还是一样
    还是这里                b = Console.Read(); 
                    b.substring(i,1); 
                    a[i] = char.Parse(b);