skip to Main Content

I wrote this program like the title says but it says system.char[] for some reason.

using System;
public class q2
{
    public static void upperNreverse(string inp)
    {
        char[] inpChar = inp.ToCharArray();
        Array.Reverse(inpChar);
        string inpString = Convert.ToString(inpChar);
        string finalString = inpString.ToUpper();
        Console.WriteLine(finalString);
    }
    public static void Main()
    {
        Console.WriteLine("Please enter the string to convert to uppercase");
        string inp = Console.ReadLine();
        upperNreverse(inp);
        
    }
}

2

Answers


  1. Convert.ToString() is not suitable for converting a char array to a string. Use the constructor new string(char[])

    Change

    string inpString = Convert.ToString(inpChar);
    

    to

    string inpString = new string(inpChar);
    
    Login or Signup to reply.
  2. Use this code,

    using System;
    public class q2
    {
        public static void upperNreverse(string inp)
        {
            char[] inpChar = inp.ToCharArray();
            Array.Reverse(inpChar);
            String inpString = new String(inpChar);
            string finalString = inpString.ToUpper();
            Console.WriteLine(finalString);
        }
        public static void Main()
        {
            Console.WriteLine("Please enter the string to convert to uppercase");
            string inp = Console.ReadLine();
            upperNreverse(inp);
    
        }
    }
    

    This is string inpString = Convert.ToString(inpChar); not the correct format for converting the char[] to string.
    Use these code

    String inpString = new String(inpChar);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search