Answers for "clear line C#"

C#
2

c# clear console line

void Method()
{
	Console.WriteLine("Test");
	Console.SetCursorPosition(0, Console.CursorTop - 1);
	ClearCurrentConsoleLine();
}

public static void ClearCurrentConsoleLine()
{
    int currentLineCursor = Console.CursorTop;
    Console.SetCursorPosition(0, Console.CursorTop);
    Console.Write(new string(' ', Console.WindowWidth)); 
    Console.SetCursorPosition(0, currentLineCursor);
}
Posted by: Guest on July-18-2021
0

how clear all line in text file and write new string in c#

if (File.Exists(ModuleListPath))
            {
                File.WriteAllText(ModuleListPath, String.Empty);
            }

            foreach (var item in list)
            {
                using (StreamWriter stream = new StreamWriter(ModuleListPath,true))
                {
                    try
                    {
                        stream.WriteLine(item);
                        
                    }
                    catch
                    {
                        trow;
                    }
                }
            }
Posted by: Guest on October-02-2020

C# Answers by Framework

Browse Popular Code Answers by Language