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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kunal VaishyaRank #990 · 2K reputationPosted May 15, 2012, 2:44 AM EDT
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");
}
VulpesRank #55 · 29.2K reputationPosted May 15, 2012, 6:51 AM EDT
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();
}
}