C
C#8mo ago
Jc!

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]);
}

}
}
}
1 Reply
Jc!
Jc!OP8mo ago
I'm also not done because I stopped half-way to try and figure out the issue but I couldn't get anywhere ohhhhhhhhh oh should I use collections? like a list collection oh ok thank you sir how do I close thx actually I still don't get it the IndexOf is a static method of the type Array
c#
for (int i = 0; i < plainText.Length; i++)
{
int position = alphabet.IndexOf(alphabet, plainText[]);
}
c#
for (int i = 0; i < plainText.Length; i++)
{
int position = alphabet.IndexOf(alphabet, plainText[]);
}
uhhh damn wow ok I gotta brush up on types in C# thx
Want results from more Discord servers?
Add your server