拍卖行控制台应用程序C# [英] Auction House console application C#
问题描述
嘿伙计们,
我正在研究一个在C#控制台应用程序中创建拍卖行系统的项目。我想知道如果我在登录后可以在控制台中实现一个菜单,你可以按下一个数字,它会显示该部分。
例如:
1 - 浏览拍卖会
2 - 参考清单
3 - 列出的项目
4 - 退出
我可能需要添加一个单独的类,如小键盘,还是可以在此代码中实现它?
这里是我到目前为止的代码:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
命名空间 ConsoleApplication1
{
class 计划
{
静态 void Main( string [] args)
{
string 输入;
Console.WriteLine( 请输入用户名);
input = Console.ReadLine();
if (input == John )
if (输入!= John)
error();
Console.WriteLine( 请输入密码);
input = Console.ReadLine();
if (input == Smith )
menu();
if (输入!= Smith )
error();
}
静态 void menu()
{
Console.WriteLine( Welcome!);
Console.ReadLine();
}
静态 void error()
{
Console.WriteLine( error);
}
}
}
你不能只是使用转换声明?像这样:
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
命名空间 ConsoleApplication1
{
class 计划
{
静态 void Main( string [] args)
{
string 输入;
Console.WriteLine( 请输入用户名);
input = Console.ReadLine();
if (输入!= John )
{
error();
}
Console.WriteLine( 请输入密码);
input = Console.ReadLine();
if (input == Smith )
menu();
if (输入!= Smith )
error();
}
静态 void menu()
{
Console.WriteLine( Welcome!);
Console.WriteLine( 请输入命令);
string input =( int )Console.ReadLine();
switch (输入)
{
case 1 :
// 运行浏览拍卖内容......
case 2 :
// 运行列表拍卖内容......
案例 3 :
// 运行列出的项目... 。
case 4 :
// 退出...
}
}
我现在刚刚写了这个,所以没有测试它......它应该可以工作。
Hey guys,
I''m currently working on a project to create an auction house system in a C# console application. I was wondering how I would be able to implement a menu in the console once I have logged in where you could press a number and it would show up that section.
For example:
1 - Browse Auction
2 - List Auction
3 - Listed Items
4 - Exit
Is it possible that I would need to add a seperate class like "keypad" or can I implement it in this code?
Here is the code I have so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string input;
Console.WriteLine("Please enter a username");
input = Console.ReadLine();
if (input == "John")
if (input != "John")
error();
Console.WriteLine("Please enter a password");
input = Console.ReadLine();
if (input == "Smith")
menu();
if (input != "Smith")
error();
}
static void menu()
{
Console.WriteLine("Welcome!");
Console.ReadLine();
}
static void error()
{
Console.WriteLine("error");
}
}
}
Couldn''t you just use a switch statement? Like so:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string input; Console.WriteLine("Please enter a username"); input = Console.ReadLine(); if (input != "John") { error(); } Console.WriteLine("Please enter a password"); input = Console.ReadLine(); if (input == "Smith") menu(); if (input != "Smith") error(); } static void menu() { Console.WriteLine("Welcome!"); Console.WriteLine("Please enter a command"); string input = (int)Console.ReadLine(); switch(input) { case 1: //Run browse auction stuff... case 2: //Run list auction stuff... case 3: //Run listed items stuff... case 4: //Exit... } }
I just wrote this now, so didn''t test it... It should work though.
这篇关于拍卖行控制台应用程序C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!