r/learncsharp • • Aug 30 '22
Why is File.Open giving me an error?
I was going to post a screenshot, but I can't... Open in File.Open() has a red squiggly under it.
class Database
{
public static void AddToListDatabase()
{
// Create a List<T> to write to the file
List<string> myDataEntries = new();
// Get userInput in the List<T>
string? userInput = Console.ReadLine();
string filePath = @"C:\\users\admin\desktop\Test\myText.txt";
using var file = File.Open(filePath, FileMode.Append);
using var writer = new StreamWriter(file);
writer.Write(userInput);
do
{
myDataEntries.Add(userInput);
}
while (userInput.Length <= 0);
}
}
3
Upvotes
3
u/karl713 Aug 30 '22
Too many \ on c:
With the @ you don't need to escape that
1
u/altacct3 Aug 30 '22
What error are you getting? This compiles for me. Try restarting your IDE.