Writing string at the same position using Console.Write in C# 2.0
Use Console.SetCursorPosition to set the position. If you need to determine it first, use the Console.CursorLeft and Console.CursorTop properties.
how to write two string and their two variables values using 1 Console.Writeline() in c#
What I think you're trying to achieve can be done like this:
Console.WriteLine("Symbol : " + parentNode.symbol + " frequency is : " + code);
i.e. Console.WriteLine(string)
But a better way would be to use the following overload Console.WriteLine(string, params object[])
:
Console.WriteLine("Symbol : {0} frequency is : {1}", parentNode.symbol, code);
And as of C# 6, you can use string interpolation (note the $
before the string):
Console.WriteLine($"Symbol : {parentNode.symbol} frequency is : {code}");
The problem is that your code is using the second overload of Console.WriteLine
but your code is not written in a way that this method can understand it.
For more information, see the MSDN documentation on the Console.WriteLine
methods:
Console.WriteLine(string)
Console.WriteLine(string, params object[])
C# Console.Write print out in text file?
I don't know why you need to write in a file in your particular case but if you want Console.WriteLine
to write in a file you may use Console.SetOut(sw);
Console.WriteLine("Hello World");
FileStream fs = new FileStream("Test.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
Console.SetOut(sw);
Console.WriteLine("Hello file");
sw.Close();
How can I write these variables into one line of code in C#?
Look into composite formatting:
Console.WriteLine("{0}.{1}.{2}", mon, da, yer);
You could also write (although it's not really recommended):
Console.WriteLine(mon + "." + da + "." + yer);
And, with the release of C# 6.0, you have string interpolation expressions:
Console.WriteLine($"{mon}.{da}.{yer}"); // note the $ prefix.
C# - Using regular Console.WriteLine formatting in a custom console extension method?
You can simple use string interpolation that was broad with c#6
Xconsole.MessageToConsole($"{Name} hits the {monster.Name} for {damage} damage. {monster.Name} now has {monster.CurrentHp} hp remaining");
Just put a dollar symbol before your string and use the variable names in the brackets.
You can read more about string interpolation here.
Rewriting characters in command window
Have a look at Writing string at the same position using Console.Write in C# 2.0
- Console.SetCursorPosition Method
- Console.CursorLeft Property
- Console.CursorTop Property
positioning and moving a shape in console application(console.write(bla bla bla);)
Have you looked at MSDN http://msdn.microsoft.com/en-us/library/system.console.aspx
1 - You will have to work out the shapes yourself, enjoy.
Here is a code that does somthing but you already have some in your example.
int pos = 0
int limit = 80
while (true)
{
StringBuilder line = new StringBuilder(limit);
for(int i = 0; i < limit; i++)
{
if (i = pos)
{
line.Append("A");
}
else
{
line.Append(" ");
}
}
Console.WriteLine(line.ToString());
if (pos = (limit - 1))
{
pos = 0;
}
else
{
pos++;
}
}
2 - You can move the console window with Console.WindowLeft
and Console.WindowsTop
3 - Shape is the wrong word and idea here, you can only read and write lines of text. You could create the impression of a moving shape by using a char say 0
or as background, populating the whole line as "blank", Then use some other chars to represent your shape. See the example above.
4 - Same as 2.
Format table in C# console application with strings of varying length
You could use the PadLeft
string function in c# to achieve what you want
more info here http://msdn.microsoft.com/en-us/library/system.string.padleft(v=vs.71).aspx
how to display a variable in console c#
It looks like this will be very broad to answer properly, so I'm going to leave it pretty abstract. You need to put reusable logic in methods. You need a "game loop" or "input loop". You need to learn about variables and passing them into methods.
You also may want to introduce a Player
class as opposed to various variables to hold separate values.
Your game loop may look like this:
ConsoleKey input = null;
do
{
var player = DoGameLogic(input, player);
PrintGameInfo(player);
input = ReadInput(player);
}
while (input != ConsoleKey.Q)
When you got all this in order and you want to make the output look nice, take a look at Writing string at the same position using Console.Write in C# 2.0, Advanced Console IO in .NET.
Related Topics
How to Include Other Files to the Output Directory in C# Upon Build
How to Get the Handle of a Console Application's Window
How to Retrieve Disk Information in C#
How to Inject Dependency to Static Class
Should I Worry About "This Async Method Lacks 'Await' Operators and Will Run Synchronously" Warning
_=> What Does This Underscore Mean in Lambda Expressions
ASP.NET MVC 3: Override "Name" Attribute with Textboxfor
How to Put a Usercontrol into Visual Studio Toolbox
Configurationmanager.Appsettings - How to Modify and Save
How to Register a .Net Dll File in the Gac
Adding Scripting Functionality to .Net Applications
Store Complex Object in Tempdata
Casting VS Converting an Object Tostring, When Object Really Is a String
How to Restrict Access to Nested Class Member to Enclosing Class
Any Way to Turn the "Internet Off" in Windows Using C#
How to Check If System.Net.Webclient.Downloaddata Is Downloading a Binary File