Hello
In a Console Application , when user wants to enter an input(For example enter his/her name),it will type Question mark(?) , instead of the characters the user typed,
how can i solve this?
thanks in advance
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted May 15, 2012, 10:51 AM
using System;
using System.Text;
class Program
{
static void Main()
{
Console.Write("Please enter your name : ");
StringBuilder sb = new StringBuilder();
char key;
while ((key = Console.ReadKey(true).KeyChar) != '\r') //continue until return pressed
{
if (key == '\b' && sb.Length > 0) // backspace
{
Console.Write(key + " " + key);
sb = sb.Remove(sb.Length - 1, 1);
}
else if (key >= 32) // printable character
{
Console.Write("?");
sb = sb.Append(key);
}
}
Console.WriteLine("\nYour name is {0}", sb.ToString());
Console.ReadKey();
}
}
Kunal VaishyaPosted May 15, 2012, 6:44 AM
static void Main(string[] args)
{
String Another ="Y";
do
{
Double I;
Double J;
Console.WriteLine("-------------------------------------------");
Console.WriteLine("Enter Value 1 and 2 For Multipication ");
Console.WriteLine("-------------------------------------------");
Console.WriteLine("Enter Value 1:");
I = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter Value 2:");
J = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Output Value :");
Console.WriteLine(I * J);
Console.WriteLine("-------------------------------------------");
Console.WriteLine("\n");
Console.WriteLine("Do you want to Another Multipication Y or N ?");
Another = Console.ReadLine();
} while (Another.ToUpper() == "Y");
}