आपको उपयोगकर्ता इनपुट की प्रत्येक कुंजी को पढ़ना होगा और फिर उस स्थान पर कर्सरपॉजिशन सेट करना होगा जिसे आप उपयोगकर्ता वजन प्रदर्शित करना चाहते हैं। इसके बाद आप इसे कंसोल पर लिखते हैं।
Console.Write("enter weight = kg");
Console.SetCursorPosition(0, 8);
metric.weightKgs = byte.Parse(Console.ReadLine());
यह सब कर्सर स्थिति के नीचे आता है और यह सटीक स्थान खोजने के साथ प्रयोग करना:
static void Main(string[] args)
{
string prompt = "Please enter your weight: ";
Console.Write(prompt + " kg");
ConsoleKeyInfo keyInfo;
string weightInput = string.Empty;
while ((keyInfo = Console.ReadKey()).Key != ConsoleKey.Enter)
{
//set position of the cursor to the point where the user inputs wight
Console.SetCursorPosition(prompt.Length, 0);
//if a wrong value is entered the user can remove it
if (keyInfo.Key.Equals(ConsoleKey.Backspace) && weightInput.Length > 0)
{
weightInput = weightInput.Substring(0, weightInput.Length - 1);
}
else
{
//append typed char to the input before writing it
weightInput += keyInfo.KeyChar.ToString();
}
Console.Write(weightInput + " kg ");
}
//process weightInput here
}
स्रोत
2017-02-28 14:02:45
मुझे लगता है कि यह संभव नहीं है। आप लिख सकते हैं "कृपया अपना वजन (किलो में) दर्ज करें:" यह स्पष्ट करने के लिए कि किस इकाई में उसे अपना वजन दर्ज करना है। –
कंसोल इनपुट सुंदर प्रारूप नहीं करता है, बस रीडलाइन() करें और स्ट्रिंग को संसाधित करें। –