I’m sure it’s another C# stupidity, right?
Apart from the fact that I’m still a beginner in this language, I don’t understand foreach
very well.
public static void test ()
{
string str = "";
foreach (string line in str)
{
Console.WriteLine(line);
}
}
using the var
keyword, that’s not what I want
I need to check string, and this is for file
CS0030: Cannot convert type 'char' to 'string'
I ask myself: why char
??
btw, this is my code.
I’m doing this to try to detect lines in a .txt file
public static readonly string file_name = "medallion.txt";
public static void file ()
{
var file = File.OpenWrite(file_name); // open the txt file
foreach (string line in File.ReadAllText(file_name))
{
if (line == string.Empty || line.StartsWith("//")) continue; // trrying to do comments
}
}
CS0030: Cannot convert type 'char' to 'string'
New contributor
Pedro Gabriel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1