Click here to Skip to main content
15,881,882 members
Everything / Console

Console

console

Great Reads

by Marco-Hans Van Der Willik
This article continues with the development of the SOLID Poker project, and covers functionality to Compare and Validate Poker Hands.
by Robert S Sharp
I'm not sure that GC would matter very much in such a simple app.But, it's either a call to Dispose on your SmtpClient after you're done using it:smtp.Dispose();or use a using:using (SmtpClient smtp = new SmtpClient{ Host = "smtp.gmail.com", Port = 587, Credentials = new...
by Sunasara Imdadhusen
MS Test Result Viewer is a free open source library to convert MS Test result (.trx) file into HTML. It is also allowed you to perform MS Test on your test container project (.dll) file. This utility will work with simple command line arguments to generate test report in HTML format with excellent U
by Athari
CsConsoleFormat library for .NET - Formatting in Console using modern technologies

Latest Articles

by M@dHatter
Access private fields from Chained Extended classes
by Kenji Elzerman
A simple tutorial with some code of how to read text from an image with Azure Computer Vision
by SiretT
Console app to share internet connection with other network interface
by Shmuel Zang
Simple Java helper class to print colored text in console window.

All Articles

Sort by Score

Console 

7 Apr 2017 by Marco-Hans Van Der Willik
This article continues with the development of the SOLID Poker project, and covers functionality to Compare and Validate Poker Hands.
19 Dec 2011 by Robert S Sharp
I'm not sure that GC would matter very much in such a simple app.But, it's either a call to Dispose on your SmtpClient after you're done using it:smtp.Dispose();or use a using:using (SmtpClient smtp = new SmtpClient{ Host = "smtp.gmail.com", Port = 587, Credentials = new...
16 Oct 2012 by Sunasara Imdadhusen
MS Test Result Viewer is a free open source library to convert MS Test result (.trx) file into HTML. It is also allowed you to perform MS Test on your test container project (.dll) file. This utility will work with simple command line arguments to generate test report in HTML format with excellent U
3 Mar 2018 by Athari
CsConsoleFormat library for .NET - Formatting in Console using modern technologies
2 Jul 2020 by Daniele Fontani
Sometimes, for learning, we need to find excuses to start a new project
21 Jul 2019 by Mustafa Kok
Easily debuggable Windows service project template written in C#
23 Dec 2011 by Dan Randolph
Builds on the existing RunRemote project to run commands on a remote server.
17 Jan 2012 by Lodewijk Pool
A quick and easy way to direct Java System.out to File and to Console.
3 Feb 2015 by CPallini
Because you are never using the input provided by the user, in your code.Try:static void Main(string[] args) { string gender; Console.WriteLine("Please enter your gender"); gender = Console.ReadLine(); if (gender == "female") ...
25 Aug 2015 by OriginalGriff
For starters, the problem is pretty simple: ReadLine is a method, and that means you need to call it as a method by appending brackets that you could put parameters in:if(Console.ReadLine() == "Attack"){ //Take away health from the goblin.}But I woudln't do that anyway.The reason...
30 Jul 2020 by DiponRoy
Making schedule jobs exe using Quartz scheduler
24 Feb 2022 by Shmuel Zang
Simple Java helper class to print colored text in console window.
29 Oct 2012 by OriginalGriff
The whole idea of DLL files is that you don't have to combine them together - they exist separately so they can be used by multiple applications without needing multiple copies.The only way to combine and EXE with the DLL files would be to include the source of the DLLs in the EXE source, and...
24 Nov 2012 by OriginalGriff
The problem is that the serial port is doing something called buffering - it is receiving the data from your microcontroller while your software is waiting for you to press a button on the keyboard. When you press the button, it fetches the next input line - which is the oldest, not the newest -...
2 Mar 2014 by Richard MacCutchan
It is a rather old fashioned (C-style) way of reading integers from the standard input stream. The call to freopen redirects that file to stdin so it can be read with the calls to getchar. A much better way of doing it would be to use fscanf or one of the STL ifstream classes. The #ifdef _WIN32...
2 Mar 2014 by CPallini
The guy is using input stream redirection in order to use getchar to perform fgetc[^] task, that is reading a character at time from a file.In the ReadInt function, blanks and newlines are skipped, then digits are then read and used to build the resulting integer, until a blank, a newline or...
31 Oct 2015 by Maciej Los
Please, read all comments to the question.Why do i recommend to change @"E:\\" to @"E:\"? Please, see: 2.4.4.5 String literals[^]Have a look here:How to: Write to a Text File (C# Programming Guide)[^]How to: Write Text to a File[^]Console.Write("Enter username: ");string Username...
19 Jan 2012 by Sergey Alexandrovich Kryukov
Nothing will work unless you eventually run System.Windows.Forms.Application.Run [EDIT] or, alternatively, System.Windows.Forms.Form.ShowDialog [END EDIT].This is where the main cycle of a Forms application is executed; and this is something which I would call Forms application anyway. No...
22 Mar 2012 by Wes Aday
Is google not working?http://msdn.microsoft.com/en-us/library/system.console.readline.aspx[^]
17 Apr 2012 by Shahin Khorshidnia
HelloLook at this: Console Code PagesMaybe this helps: C#: How to print a unicode string to console?
10 Mar 2013 by wingzero007
By keeping the same project, you can change the output type:1. Go to the properties of your project (right click on the project in VS).2. In the context menu, choose properties.3. In the window that appears, Select the Application tab (Should be the first one by default).4. Change the...
17 Jul 2013 by Pheonyx
Run it and find out! we are not here to do your testing for you!
14 Oct 2013 by Richard MacCutchan
It's not totally clear what your problem is, but does this help?while (true){ Console.Write("What's the magic word? "); string word = Console.ReadLine(); if (word == "shazam") { Console.WriteLine("You guessed it!"); break; } else { ...
1 Mar 2014 by BillWoodruff
When you use the {#n} substitution place-holder in a string, there must be a number of arguments, after the string, which correspond to the zero-based index number inside the {}.When you write: Console.WriteLine("The Greatest of 3 numbers is {1}",_secondNumber);The compiler looks for a...
18 Mar 2014 by OriginalGriff
Yes, any C# application is managed code - it is intimately tied to the .NET framework, so you will need that or a replacement such as one of the Mono variants to run any C# program, beit console or Winforms.You must have the appropriate .NET framework installed to run any .NET application.
11 Nov 2014 by Jochen Arndt
When using Linux, you can use the framebuffer[^]. To show an image using the framebuffer:Open the framebuffer device (/dev/fbX)Get the device information using ioctl calls with FBIOGET_FSCREENINFO and FBIOGET_VSCREENINFOIf necessary convert the image to the color depth of the...
30 Nov 2014 by Emilio Garavaglia
It is much more a problem relatd to the console capability than to the programming language.As far the console is ANSI compatible, the following code can be used:[{attr1};...;{attrn}m0 Reset all...
3 Feb 2015 by nagendrathecoder
The code is incorrect here.You are saving user input in a string variable and comparing bool variable male (which is always true).You need to compare on string variable like:if(gender == "Male") //print maleelse if(gender == "Female") //print femaleelse //print improper input
2 Nov 2015 by George Jonsson
If your only concern is to check if the last character is a digit or alpha, you can use the method Char.IsDigit[^]Likebool isDigit = Char.IsDigit(str, str.Length-1);
16 Dec 2015 by Richard Deeming
Use int.TryParse[^] to attempt to convert the user's input to a number.Use the OR operator (||) to test whether the number is outside of the range. It can't be both "less than or equal to 20" and "greater than or equal to 50" at the same time!Add a loop to re-prompt the user until you...
16 Dec 2015 by phil.o
A do..while loop could do it:int number;bool ok;do { Console.WriteLine("Enter an integer value between 20 and 50, exclusive"); ok = Int.TryParse(Console.ReadLine(), out number); if (!ok) { number = 0; }} while ((number = 50))This will keep...
23 Feb 2016 by Patrice T
The output is correctYour mistake is that you sort a list of strings, not a list of numbers.so "6" fall between "54" and "77"a sort on strings is alphabetical.
1 Mar 2016 by Garth J Lancaster
I'm wondering if its because Console.ReadKey() 'blocks' until it actually gets input - a nicer way of doing this may be something like :- while (true){ if (Console.KeyAvailable) { ConsoleKeyInfo cki = Console.ReadKey(); // There's also a Console.ReadKey(true) variant...
27 Sep 2016 by David_Wimbley
Im not terribly clear on what you are trying to accomplish. I think what you are asking is what is the best way to do the same operation to 170 different devices.You should look at threading/Tasks in .net.var tasks = new list();var deviceEndpoints = new List();foreach...
14 Aug 2019 by DaveAuld
Object inspection with %O in the console output
7 Oct 2019 by phil.o
You do not need to create the file before using WriteAllLines. It is possible you run into a race condition by using WriteAllLines just after Create. You could try: if (!File.Exists(filePath)) { List output = new List(); ...
21 Feb 2022 by Illya Reznykov
How to update EmailMessage properties that don't have public setters
9 Mar 2022 by SiretT
Console app to share internet connection with other network interface
18 Dec 2011 by Sergey Alexandrovich Kryukov
You should use System.Console.ReadKey(true), but in a separate thread, that's it. This call will block the calling thread until some key is hit, and no feedback will be shown, thanks to this method's parameters. Another thread will show output without pause. Pretty simple.I'm not sure...
18 Jan 2012 by Sergey Alexandrovich Kryukov
I think this would be easier:Define the Console methods you use with exact same name and signatures://[EDIT...]internal class UiConsole { internal UiConsole(TextBox sink) { this.Sink = sink; } internal string void WriteLine(string value) { /* this is easy */} ...
10 Feb 2012 by Christian Graus
Process.Start(...
31 May 2012 by Maciej Los
Have a look here:http://www.libxl.com/[^]http://code.msdn.microsoft.com/office/CppAutomateExcel-be36992e[^]http://hi.baidu.com/koko200147/blog/item/4ae3908be52f98739f2fb48d.html[^]
9 Jul 2012 by Jackie00100
okay fixed this my self after finding the right imports...EDIT:Source code:using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using...
20 Jul 2012 by Christian Graus
To register a COM dll, you call regsvr32. There's no complex code or library required. ShellExecute is all you need.
26 Jul 2012 by John Orendt
Visits to configured web sites in every configured interval and logs connectivity.
5 Dec 2012 by OriginalGriff
A very, very simple Google search woudl have found you this info a lot quicker than asking here - it's not as if it's a new question.Have a look at this: http://programmers.stackexchange.com/questions/92339/when-do-you-use-a-struct-instead-of-a-class[^] which covers it pretty well.In...
8 Apr 2013 by Sergey Alexandrovich Kryukov
This is a well-known problem related to some class which is usually called "BigInteger" or "BigInt".These are some of the implementations:http://sourceforge.net/projects/cpp-bigint/[^],https://mattmccutchen.net/bigint/[^],https://github.com/technophilis/BigIntegerCPP[^].You can try...
19 Jul 2013 by Sergey Alexandrovich Kryukov
In addition to the Solution 1:One ultimate requirement to handling exceptions: catch them all on the top stack frame of each thread. Event-oriented UI threads have their own twist: all exceptions should be caught in the main even cycle of the thread. Usually, UI libraries have the special...
21 Sep 2013 by V.Lorz
Some times it's a good idea trying to get some background about what you're willing to do. For downloading e-mails from the server you use what is called e-mail protocol. Two of the most commonly used ones are POP3 and IMAP. With this in mind you can go and search for something like "pop3 client...
27 Nov 2013 by OriginalGriff
You can't cast a ListNode to an integer - that's just silly! foreach (object s in listOfNodes) sum += (int)s;s is a ListNode - because that is what your GetEnumerator method returns: public IEnumerator GetEnumerator() { ...
1 Dec 2013 by Sergey Alexandrovich Kryukov
You are perfectly right. First thing to note is: the difficulty you pointed out is a good evidence of the fact that your requirement makes little to no practical sense and should not be imposed for any real-life task. Also, the formulation of the question is inaccurate: in programming, even if...
20 Dec 2013 by Sergey Alexandrovich Kryukov
Please see my comment to the question. If this is really a console, a text console in a standard console-only application type, there is no "refresh" or some usual even-oriented features. You should simply redraw the whole console "screen" again, the same way as you did it before modification of...
20 Dec 2013 by CPallini
In order to accomplish your task you might use the Console Functions[^] on Windows, and ncurses on Linux (see, for instance "NCURSES-Programming-HOWTO"[^].
12 Feb 2014 by TrushnaK
try this simple code:-string[] fileArray = Directory.GetFiles(@"c:\Dir\");or class Program{ static void Main() { // Put all file names in root directory into array. string[] array1 = Directory.GetFiles(@"C:\"); // Display all files. ...
12 Feb 2014 by Naufel Basheer
include using System;using System.IO;string[] files = Directory.GetFiles(@"C:\");foreach (string name in files) { Console.WriteLine(name); }
12 Feb 2014 by praveen_07
string[] array1 = Directory.GetFiles(@"C:\");foreach (string name in array1) { Console.WriteLine(name); }Regards,Praveen
17 Feb 2014 by Sergey Alexandrovich Kryukov
I already answered: How to insert elements into an existing string array[^].With your behavior, you should rather leave this site. Helping you is totally useless.—SA
21 Apr 2014 by OriginalGriff
Encryption always produces "special characters" because it converts the input (from text or whatever it was) to a collection of bytes - which aren't characters, they are eight bit values which may contain valid characters but are more likely not to.Try converting the byte array to Base64[^]...
7 May 2014 by DamithSL
http://www.dotnetperls.com/fibonacci[^]
9 Jun 2014 by Sergey Alexandrovich Kryukov
POP3 is for retrieving and deleting mail, not for sending. As to the "problem in POP3 namespace", you did not provide any information. I would say, namespaces are generally irrelevant to any problems.—SA
29 Oct 2014 by Garth J Lancaster
you could search for this yourself ... try this http://www.codeproject.com/Articles/646296/A-Cross-platform-Csharp-Class-for-Using-INI-Files[^]
29 Oct 2014 by OriginalGriff
.INI files are somewhat out of date - they stopped being the recommended way of doing things with Windows 95, and that was nearly twenty years ago! :laugh:However, if you must...You can use the Windows methods which will still work: [DllImport("kernel32")] private static...
16 Nov 2014 by Jochen Arndt
An example can be found at cplusplus.com: Masking password input[^].
31 Oct 2015 by BillWoodruff
To add to what Maciej has shown you here:There are several ways to create a "blank" File can be created in C#:1.File.Create(pathName); // will leave the created File openSince leaving the File open is often not desired:using (File.Create(pathName))using (File.Create(pathName))...
15 Nov 2015 by Sergey Alexandrovich Kryukov
Yes, you will always get 0% and then 100%, because this call is just one operations which is started at 0% and the method returns, it's already 100%. You can do it in parts only of you implement your own copy. Open source and target files and copy data in smaller chunks. Then you would be able...
23 Feb 2016 by F-ES Sitecore
This will convert the string to a number when doing the comparison;if (int.Parse(a.ElementAt(j)).CompareTo(int.Parse(a.ElementAt(j + 1))) > 0)However it will error if you add somenone non-numeric to the list. For a number sort you're best using LinkedList x = new...
13 Mar 2016 by M. van der Corput
Simple task based spinner for a console application
15 Jun 2016 by CHill60
GetProcessesByName takes the process name, not a regex that the process name matches.You probably want something like this instead...foreach (Process P in Process.GetProcesses()){ if (P.ProcessName.StartsWith("U", StringComparison.CurrentCultureIgnoreCase)) P.Kill();}
30 Jun 2016 by Philippe Mori
DirectoryInfo related stuff seems useless in your code.In your code, there is no code that send SMS so it is not possible to tell you where the problem is. However, it would be very easy for you to put a breakpoint on the code that does send the SMS and see why a message is sent.That...
28 Dec 2016 by Ramza360
In the AI method, you're allowing multiple choices since there are more than one if blocks. So any of the if blocks can evaluate to true, setting the additional 'O'.You have potentially 10 points due to the 10 if blocks, most likely they all would not evaluate as true (this includes the else...
3 Mar 2018 by ruben rick
This simple code displays a perlin noise like example.
22 Mar 2019 by RickZeeland
After this line: foreach (FileInfo fileD in destFiles) you should first compare the file names for equality, and only then do the copying: If (file.Name.equals(fileD.Name)) { // your code ... } If you want something more advanced you could try Gerry's solution which involves using LINQ.
26 Feb 2020 by CPallini
You know it works this way Open the original file for reading and read it line by line. Copy only the wanted lines to another file (the 'output' file, that is open for writing) At the end of the process, delete the original file and rename...
17 Oct 2020 by OriginalGriff
You need to set up a loop around your existing code: string reply = ""; do { ...your code here ... Console.Write("Do you want to exit now? (Y/N)"); reply = Console.ReadLine().Trim().ToUpper(); } while...
25 Mar 2021 by Richard MacCutchan
Yes, because your print statement is incorrect. it should include the item reference for the variable: Console.WriteLine("Days Left are: {0} ", dayLeft);
2 Aug 2021 by Tony Hill
It is because you created your Cell_Phone class with a constructor requiring three parameters but only pass one when the object is instantiated in Main class you only pass a brands enum. As the constructor seems to populate the fields depending...
18 Feb 2022 by Richard MacCutchan
The first thing you need is a Python library that can handle these files. The first link thatGoogle finds is GitHub - globocom/m3u8: Python m3u8 Parser for HTTP Live Streaming (HLS) Transmissions[^].
13 Nov 2022 by Kenji Elzerman
A simple tutorial with some code of how to read text from an image with Azure Computer Vision
16 Jan 2023 by M@dHatter
Access private fields from Chained Extended classes
15 Aug 2016 by njammy
Try this inside your While loop to iterate over each column of each row regardless of the column name. If you need to access only certain columns, provide the column name instead of its index:For i = 0 To rdr.FieldCount - 1 Console.WriteLine(rdr.GetName(i), dr(i)))Next
15 Dec 2011 by Joel Whatley-
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { static Random newletter = new Random(); static void Main(string[] args) { string[]...
15 Dec 2011 by Firo Atrum Ventus
Those errors appears because inputletter is a System.ConsoleKeyInfo[^] and you're trying to compare it with a string.You should use KeyChar[^] property of inputletterinputletter = Console.ReadKey();if (inputletter.KeyChar.ToString() == alphabet[lol]){}
14 Jan 2012 by Sergey Alexandrovich Kryukov
You certainly can. First, let me you assume you have source codes of all both projects, then you can freely merge them. I would advice you not to mess with console. Instead, simulate console with your .NET application using some UI control. I usually use ListBox (one item per text line) which is...
17 Jan 2012 by OriginalGriff
Why?Replace it with string.Format:Console.WriteLine( "{0} (quantity {1}) was replaced by {2}, (quantity {3}).", item.Description, item.Quantity, replacement.Description, replacement.Quantity);myTextBox.Text = String.Format( "{0} (quantity {1}) was replaced by...
17 Jan 2012 by RDBurmon
I think you are looking for this StringBuilder str=new StringBuilder();str.AppendFormat("{0} (quantity {1}) was replaced by {2}, (quantity {3}).", item.Description, item.Quantity, replacement.Description, ...
19 Jan 2012 by MikeM75
I have a program that is nearly completed and written as a C# Console application. I do this because this program works with directories a lot and I am most comfortable writing console applications.What I need is a way to have a popup form launched from my console application. The form...
21 Feb 2012 by SandipG
You have declared line as char line[28]then why 29 in the following line?inFile.getline(line,29);
19 Mar 2012 by Mukit, Ataul
sometimes console applications give runtime error when you declare static varialbes, so here is a solution how to deal with it
17 Apr 2012 by Eugene Sadovoi
The solution to your problem explained in details at this link[^].The code from this blog is here (I have nothing to do with this code, it is simply cut/paste):using System;using System.Runtime.InteropServices;public class Test { public static void Main() { ...
23 May 2012 by lukeer
Not nice, but seems to work:I try to read Console.BufferHeight and if that throws an exception, then there is no console and I use a Form for output.
11 Sep 2012 by Sergey Alexandrovich Kryukov
Please see the comments to the question by Zoltán Zörgő and mine. You did not provide relevant information on what happens. One of the most apparent thing which might happen is this: some executable files in this directory are loaded for execution and are actually executed when you try to...
28 Sep 2012 by fjdiewornncalwe
This makes zero sense. A web browser is by nature graphical. How do you propose to use a graphical forms component from a non graphical console? Because you are interacting with the page you get back, there really is no point in doing that.
28 Sep 2012 by ridoy
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/57a7cacb-9b89-4d69-a3f3-ff143e0ad2fc[^]http://stackoverflow.com/questions/6324810/using-webbrowser-in-a-console-application[^]http://stackoverflow.com/questions/4269800/webbrowser-control-in-a-new-thread/4271581#4271581[^]http:...
4 Nov 2012 by OriginalGriff
Then you had best knuckle down and get on with it, hadn't you?We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more...
5 Nov 2012 by Richard MacCutchan
It should be clear that your assignment will not get any credit if:o The assignment is submitted after due date.o The submitted assignment does not open or file corrupt.o The assignment is full or partially copied from (other student or ditto copy from handouts or internet).o Student ID...
8 Nov 2012 by gopal pradhan
You will get a precompiled site by publishing as well as by creating a setup.exe (setup and deployment)The difference between the two is that:Publishing: you right click on the website and click on 'Publish Web Site'. Here you can specify a folder where the precompiled website will be...
4 Jan 2013 by Andreas Gieriet
This is mainly a parsing task, not really suited for a C++ beginner.An expert in parsing would solve this within a few hours - a complete novice might take months to get it somehow done.I would choose a different topic, depending on your personal interests or hobby.Think also of where C++...
15 Jan 2013 by David_Wimbley
Im going to make the assumption (Dangerous in know) that i think i know what it is you are requesting.The following will store all your files that you end up copying with your last write time constraint == today.StringBuilder copiedFiles = new StringBuilder();Along with your file copy,...
13 Feb 2013 by Alan N
It turns out there is some Windows API trickery for this situation.See the response by Willy Denoyette in http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/tree/browse_frm/thread/c72efe6c358eca9e/588a7bf4cfb4832[^]using System;using...
19 Jul 2013 by Ron Beyer
I would fail with a generic error then write detailed failure info to the application log or an error reporting file. Best practice for handling exceptions is to only handle exceptions that you can do something about it, the rest you pass up the call stack (aka, don't catch them). You can...