Caesar Cipher C# error?

I followed the youtube tutorial because I’m still shaky on this code. I get to step ten and the return is:
“$ dotnet run
Enter your secret message.
Your secret message is: System.Char

Below is my code. Can anyone tell me why I’m getting System.Char[]?

using System;

namespace CaesarCipher
class Program
static void Main(string args)
char alphabet = new char {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’};

  Console.WriteLine("Enter your secret message.");
  string input = Console.ReadLine();
  char[] secretMessage = input.ToCharArray();

  char[] encryptedMessage = new char[secretMessage.Length];

  for (int i = 0; i < secretMessage.Length; i++)
      char letter = secretMessage[i];
      int letterPosition = Array.IndexOf(alphabet, letter);
      int newLetterPosition = letterPosition + 3;
      char letterEncoded = alphabet[newLetterPosition];
      encryptedMessage[i] = letterEncoded;

  string encodedString = String.Join("", encryptedMessage);
  Console.WriteLine($"Your secret message is: {encryptedMessage}");



Console.WriteLine($"Your secret message is: {encryptedMessage}");

encryptedMessage is a System.char array, not a string.
Glance up a line to find something which might fit the bill.

Hope that helps


HAHA! Oh my gosh! I can’t believe I did that! (…I can.)
I looked at it so long. HOW DID I MISS THAT?!

Thank you so much! Having a second set of eyes on code is a life-saver!!!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.