0

This is my whole code :

using System;

namespace start
{
class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            try
            {
                string nevim = "";                          // prázdná proměnná pro zbytek
                Console.WriteLine("zadej číslo, které chceš převést do binární soustavy: ");

                ulong vstup = ulong.Parse(Console.ReadLine());  // uložíme vstup do proměnné
                while (vstup > 0)                           //pokud je vstup větší než 0
                {
                    ulong pocet = vstup % 2;                  // zjistí zbytek po dělení dvojkou
                    nevim = nevim + pocet;                  //   do proměnné přidá zbytek
                    vstup = vstup / 2;                      //   zadané číslo vydělí 2        


                }
                char[] array = nevim.ToCharArray();        
                Array.Reverse(array);                       //otočí výsledek
                Console.WriteLine(array);
                Console.WriteLine(array + "test");



                Console.ReadKey();
            }

            catch
            {
                Console.Clear();
                Console.WriteLine("nastala nějaká chyba TYY GEJI");
                Console.WriteLine("stiskni libovolné tlačítko pro pokračování");
                Console.ReadKey();
                Console.Clear();
            }
        }
    }
}
}

i tried "To.CharArray convert method" to reverse the string, when i try to get the output its ok, for example:

input = 123

output:

1111011

but when i try to add something to output like:

Console.WriteLine(array + "test");

the output is:

System.Char[]test

and i want this as output:

1111011 test

Any ideas?

beginner
  • 7
  • 2
  • 4
    `new string(array)` will turn your char array into a string – juharr Oct 24 '19 at 17:39
  • 1
    Possible duplicate of [printing all contents of array in C#](https://stackoverflow.com/questions/16265247/printing-all-contents-of-array-in-c-sharp) – ggorlen Oct 24 '19 at 17:40

2 Answers2

0

You trying to add string to char[]. In this case .net is trying to convert both values to the same type by calling array.ToString() behind the scene. By default it returns type name. In your case it is System.Char[]. To get expected result you should either create string from your array:

Console.WriteLine(new String(array) + "test");

or convert "test" to array and concatenate arrays. Check Merging two arrays in .NET for the sample

0

Just do:

Console.WriteLine(new string(array) + "test");
Ε Г И І И О
  • 11,199
  • 1
  • 48
  • 63