console.writeline

Aligning text output by the console?

别等时光非礼了梦想. 提交于 2019-11-30 23:05:36
What I want to do, is make the text that I output via the Console.Writeline method line up perfectly regardless of length. Example: // Notice that no matter the length of the text on the left, // the text on the right is always spaced at least 5 spaces. this is output text this is also output text output text my output text Am I going to have to write my own method for this, or does .Net contain something that I can use already? Something like this should work for you. Hopefully you can adapt it to your needs. string[] outputs = { "this is output", "this is also output", "output", "my output"

Console.Writeline basics

最后都变了- 提交于 2019-11-30 17:13:02
I have a question about the following code: class CurrentDate { static void Main() { Console.WriteLine(DateTime.Now); } } Documentation says: Writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information. So my question is: How come WriteLine knows the text representation of DateTime object? I mean, if I create my own object from my own class, how would it know how to convert the value to text? And even more, how does it know what the value is? How can you define "value" of an

c# attribute over main

三世轮回 提交于 2019-11-30 13:02:30
Someone asked me a question as to how we can print line no 1 line no 2 line no 3 Without changing a main method which reads static void Main(string[] args) { Console.WriteLine("line no 2"); } Now one approach was to have multiple entry points for the console application. However I tried another approach which goes as follows : class Program { [Some] static void Main(string[] args) { Console.WriteLine("line no 2"); } } class SomeAttribute : Attribute { public SomeAttribute() { Console.WriteLine("line no 1"); } ~SomeAttribute() { Console.WriteLine("line no 3"); } } When I apply a breakpoint on

Console.Writeline basics

∥☆過路亽.° 提交于 2019-11-30 00:41:11
问题 I have a question about the following code: class CurrentDate { static void Main() { Console.WriteLine(DateTime.Now); } } Documentation says: Writes the text representation of the specified array of objects, followed by the current line terminator, to the standard output stream using the specified format information. So my question is: How come WriteLine knows the text representation of DateTime object? I mean, if I create my own object from my own class, how would it know how to convert the

(Console.BufferHeight) I can't see/scroll to see all the console output with Console.WriteLine

霸气de小男生 提交于 2019-11-29 13:18:13
When I run this code, the number at the top of the output window is 99701. Why don't I get to see all the way through 1? I actually see all the numbers getting outputted, but on the console window, I can only SCROLL high enough to see 99701 (I'm guessing). I'm using Visual C# express on Vista Home. :D using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using utilities; namespace Testing_Project { class Program { static void Main(string[] args) { List<string> myList = new List<string>(); for (int x = 0; x < 100000; x++)

Is console.writeline thread safe? [duplicate]

我与影子孤独终老i 提交于 2019-11-29 09:03:03
Possible Duplicate: Calling Console.WriteLine from multiple threads Just want to know if multiple threads call the same console.writeline, will it cause deadlock? ClosureCowboy It's safe! From MSDN : Console I/O Streams [...] I/O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams. 来源: https://stackoverflow.com/questions/4812508/is-console-writeline-thread-safe

C# clear Console last Item and replace new? Console Animation

僤鯓⒐⒋嵵緔 提交于 2019-11-29 07:21:04
问题 The following CSharp Code(just sample): Console.WriteLine("Searching file in..."); foreach(var dir in DirList) { Console.WriteLine(dir); } Prints Output As: Searching file in... dir1 dir2 dir3 dir4 . . . Question? How can I get the output as Searching file in... dir1 (then clear dir1 and print dir2 and so on)All next dir name wiil replace the previous dir 回答1: If your problem is clearing the console then use the method Console.Clear(); , if it's not, use this to overwrite the last line;

(Console.BufferHeight) I can't see/scroll to see all the console output with Console.WriteLine

情到浓时终转凉″ 提交于 2019-11-28 07:14:20
问题 When I run this code, the number at the top of the output window is 99701. Why don't I get to see all the way through 1? I actually see all the numbers getting outputted, but on the console window, I can only SCROLL high enough to see 99701 (I'm guessing). I'm using Visual C# express on Vista Home. :D using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using utilities; namespace Testing_Project { class Program { static

Is there a way to delete a character that has just been written using Console.WriteLine?

人走茶凉 提交于 2019-11-28 04:06:49
Is there any way to delete the last character from the console, i.e. Console.WriteLine("List: apple,pear,"); // Somehow delete the last ',' character from the console. Console.WriteLine("."); // Now the console contains "List: apple,pear." Sure, I could create a string first then print that to the console, but I'm just curious to see if I can delete characters directly from the console. "\b" is ASCII backspace. Print it to back up one char. Console.Write("Abc"); Console.Write("\b"); Console.Write("Def"); outputs "AbDef"; As pointed out by Contango and Sammi, there are times where overwriting

Is console.writeline thread safe? [duplicate]

戏子无情 提交于 2019-11-28 02:24:06
问题 Possible Duplicate: Calling Console.WriteLine from multiple threads Just want to know if multiple threads call the same console.writeline, will it cause deadlock? 回答1: It's safe! From MSDN: Console I/O Streams [...] I/O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams. 来源: https://stackoverflow.com/questions/4812508/is-console-writeline-thread-safe