console.writeline

c# attribute over main

梦想的初衷 提交于 2019-12-18 15:48:29
问题 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

Calling Console.WriteLine from multiple threads

五迷三道 提交于 2019-12-17 03:20:06
问题 Why does Console.WriteLine work from multiple threads? 回答1: The console class handles the thread synchronization for you. From the documentation of Console: I/O operations using these streams are synchronized, which means multiple threads can read from, or write to, the streams. 回答2: There is a bug in .NET 4.5 CLR which makes Console.WriteLine not work from multiple threads if you use Console.ReadKey. It is fixed in some Windows versions, but in 8.1 Windows Update does not find it yet.

How can I type “{0}” more quickly in Visual Studio?

痴心易碎 提交于 2019-12-13 09:44:35
问题 In C#, it's common to have to type {0} , {1} , etc. when formatting strings with string.Format() or Console.WriteLine(). Considering its frequency, it's an awkward set of key strokes. But despite my searches, I couldn't find any sort of shorthand or hotkey to automatically insert it in Visual Studio. Has anyone figured out something to expedite the process? 回答1: You can create the following command (C#) with my Visual Commander extension to insert text and then assign a keyboard shortcut to

Console.WriteLine is not working after Resolve()

我与影子孤独终老i 提交于 2019-12-13 04:17:24
问题 This code gives no error or warning during execution. but it ignores the console.read() function, i am newer with windsor. is it really a bug or the simple behavior of windsor ? using System; using Castle.Windsor; using Castle.MicroKernel.Registration; namespace CastleProject { class Program { internal interface ILogger { void log(string message); void showMethod(); } internal interface Ishowing { void checkInterface(); } class Logger : ILogger { public void log(string message) { Console

Why is F# printfn not implemented in terms of Console.WriteLine?

喜夏-厌秋 提交于 2019-12-12 13:03:32
问题 I noticed an unexpected behavior when using F# printfn. It seems to break up the format string into chunks and call Console.Write multiple times for each call to printfn. I would expect it to format the entire string and then call Console.WriteLine once. I noticed this because I am intercepting the standard Console Output using Console.SetOut call with my own TextWriter which tries to prefix every line of output with a time stamp and some additional custom text. What gives? 回答1: Here's my

C# Console.WriteLine prints a Char type as Integer [duplicate]

≡放荡痞女 提交于 2019-12-11 13:42:55
问题 This question already has answers here : Conditional operator cannot cast implicitly? (3 answers) Closed last year . I dont understand why is this printing char data type once as char, other time as integer static void Main(string[] args) { char x = 'A'; int i = 0; Console.WriteLine(x); // A Console.WriteLine(true ? x : 0); // 65 ??? Console.WriteLine(false ? i : x); // 65 ??? Console.ReadLine(); } I would expect output to be A, A, A but the output of above is A, 65, 65 . Why? 回答1: The

How to output windows Alt keycodes in a C# console app

不羁岁月 提交于 2019-12-11 04:09:37
问题 How can I output Windows Alt key codes to the console in a C# console app using Console.WriteLine()? I would like to output characters such as those used for creating boxes. I can do so manually in a command prompt by holding alt and typing in the appropriate number such as Alt+205, Alt+187, etc. Thanks 回答1: I suppose the easiest way would be to include them directly in your string literals within your source code: Console.WriteLine("═╗"); 回答2: EDIT: I'm sorry - my answer is incorrect. ASCII

How to read sql generated by NHibernate in Visual Studio

怎甘沉沦 提交于 2019-12-10 10:53:43
问题 According to what I know, there are 3 ways to read the sql script generated by NHibernate: 1. log4net 2. sql profiler 3. show_sql = true Here I just want to talk about 3rd one for it's said that I can read the sql in the output window in Visual Studio. But whatever I do, I can see nothing?! Becasue some guy said the "show_sql = true" just means "Console.WriteLine()", so I post a question here. I have to say I don't get what I want, so here I summarize my questions: in the output window in an

Why does Console.WriteLine() function miss some characters within a string?

杀马特。学长 韩版系。学妹 提交于 2019-12-09 07:48:33
问题 I have a string, declared as: string text = "THIS IS LINE ONE "+(Char)(13)+" this is line 2"; And yet, When I write Console.WriteLine(text); , the output is: this is line 2E Why is this behaviour happening? Or is it because I'm being stupid and missing something obvious? Why does it not print: THIS IS LINE ONE [CR] //where the CR is a non printed character this is line 2 EDIT Please note: this is NOT a 'how do I add a carriage return' question. 回答1: (char)13 is a carriage return (To the left

Aligning text output by the console?

五迷三道 提交于 2019-12-09 00:50:35
问题 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? 回答1: Something like this should work for you. Hopefully you can