类似这样:
#include <stdio.h>#include <stdlib.h>
void shutdown()
{
char type
printf ("您确定退出吗?(Y/N)")
fflush(stdin)
scanf ("%c", &type)
if (type=='Y' || type=='y')
exit(0)
}
int main()
{
int a
while (scanf ("%d", &a)!=EOF){
if (a==4){
shutdown()
}
}
return 0
}
示例:
do{
byte.TryParse(Console.ReadLine(),outoption)
if(option==1){
write(path)
}elseif(option==2){
read(path)
}else
Console.WriteLine("Wrongoption")
}while(option!=1||option!=2)
if(option==1){
write(path)
break
}elseif(option==2){
read(path)
break
}else
扩展资料
C#在WinForm中打开控制台显示
例:
namespace测试使用
{
publicpartialclassForm1:Form
{
[System.Runtime.InteropServices.DllImport("kernel32.dll",SetLastError=true)]
[return:System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
staticexternboolAllocConsole()
[System.Runtime.InteropServices.DllImport("Kernel32")]
publicstaticexternvoidFreeConsole()
publicForm1()
{
InitializeComponent()
}
privatevoidForm1_Load(objectsender,EventArgse)
{
AllocConsole()//开启控制台
}
}
}
这么写就行了using Systemclass Program
{
static void Main(string[] args)
{
Console.WriteLine("按a键退出")
while (Console.ReadKey().KeyChar != 'a')
{
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)