Jc!
Jc!
CC#
Created by Jc! on 4/25/2024 in #help
I'm getting a red squiggly line under alphabet.IndexOf() and I don't understand what is the problem
I was converting my python code to C# code to see my skill in both and I got a issue on the alphabet.IndexOf() something about overloaded CS1501 is the errors name also could it be that it's because there is a index argument inside this is what it looks like alphabet.IndexOf(plainText[i]) one more thing the program is a cipher program here is the code
c#
using System.ComponentModel;

namespace cipher
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("Type encode to encrypt, type decode to decrypt: ");
string direction = Console.ReadLine();

Console.WriteLine("Type your message:");
string text = Console.ReadLine();

Console.WriteLine("Type the shift number:");
string shift = Console.ReadLine();
}

void encrypt(string plainText, string shiftAmount)
{
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'};

string cipher_text;

for (int i = 0; i < plainText.Length; i++)
{
int position = alphabet.IndexOf(plainText[i]);
}

}
}
}
c#
using System.ComponentModel;

namespace cipher
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("Type encode to encrypt, type decode to decrypt: ");
string direction = Console.ReadLine();

Console.WriteLine("Type your message:");
string text = Console.ReadLine();

Console.WriteLine("Type the shift number:");
string shift = Console.ReadLine();
}

void encrypt(string plainText, string shiftAmount)
{
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'};

string cipher_text;

for (int i = 0; i < plainText.Length; i++)
{
int position = alphabet.IndexOf(plainText[i]);
}

}
}
}
18 replies