| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 904 人关注过本帖
标题:可以近来看一下!
只看楼主 加入收藏
chali
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-1-11
收藏
 问题点数:0 回复次数:6 
可以近来看一下!
Do 循环: Do loop.cs





using System;
class Doloop {
public static void Main() {
string myChoice;
do {
// Print A Menu
Console.WriteLine("My Address Book\n");
Console.WriteLine("A - Add New Address");
Console.WriteLine("D - Delete Address");
Console.WriteLine("M - Modify Address");
Console.WriteLine("V - View Addresses");
Console.WriteLine("Q - Quit\n");
Console.WriteLine("Choice (A,D,M,V,or Q): ");

// Retrieve the user's choice
myChoice = Console.ReadLine();
// Make a decision based on the user's choice
switch(myChoice) {
case "A":
case "a":
Console.WriteLine("You wish to add an address.");
break;
case "D":
case "d":
Console.WriteLine("You wish to delete an address.");
break;
case "M":
case "m":
Console.WriteLine("You wish to modify an address.");
break;
case "V":
case "v":
Console.WriteLine("You wish to view the address list.");
break;
case "Q":
case "q":
Console.WriteLine("Bye.");
break;
default:
Console.WriteLine("{0} is not a valid choice", myChoice);
}

// Pause to allow the user to see the results
Console.Write("Press any key to continue...");
Console.ReadLine();
Console.WriteLine();
} while (myChoice != "Q" && myChoice != "q"); // Keep going until the user wants to quit
}
}






为什么编译不能通过呢?
搜索更多相关主题的帖子: public Choice 
2005-03-20 21:34
chali
Rank: 1
等 级:新手上路
帖 子:20
专家分:0
注 册:2005-1-11
收藏
得分:0 
对了,里面的 default   到底是什么意思呀!!!!!!!!!!!!!

2005-03-20 21:42
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
default 代表除了所有case的条件以外。

你怎么通不过?错误提示是什么?
2005-03-23 21:41
nyzfl
Rank: 1
等 级:新手上路
帖 子:278
专家分:0
注 册:2005-3-21
收藏
得分:0 

using System; class Doloop { public static void Main() { string myChoice; do { // Print A Menu Console.WriteLine("My Address Book\n"); Console.WriteLine("A - Add New Address"); Console.WriteLine("D - Delete Address"); Console.WriteLine("M - Modify Address"); Console.WriteLine("V - View Addresses"); Console.WriteLine("Q - Quit\n"); Console.WriteLine("Choice (A,D,M,V,or Q): ");

// Retrieve the user's choice myChoice = Console.ReadLine(); // Make a decision based on the user's choice switch(myChoice) { case "A": case "a": Console.WriteLine("You wish to add an address."); break; case "D": case "d": Console.WriteLine("You wish to delete an address."); break; case "M": case "m": Console.WriteLine("You wish to modify an address."); break; case "V": case "v": Console.WriteLine("You wish to view the address list."); break; case "Q": case "q": Console.WriteLine("Bye."); break; default: Console.WriteLine("{0} is not a valid choice", myChoice); break; }

// Pause to allow the user to see the results Console.Write("Press any key to continue..."); Console.ReadLine(); Console.WriteLine(); } while (myChoice != "Q" && myChoice != "q"); // Keep going until the user wants to quit } } 你就差这一步,仔细看以下


My-Blog地址:http://fenglin.
2005-03-24 08:59
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
不用了,因为default已经是最后一个switch了,不用break都会跳出。
2005-03-24 10:04
bingxue
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-3-23
收藏
得分:0 
nyzfl--这位大哥说的正确呀,我刚实现过了呀.

2005-03-24 22:48
shenying
Rank: 1
等 级:新手上路
帖 子:50
专家分:0
注 册:2005-3-24
收藏
得分:0 

2005-03-25 09:08
快速回复:可以近来看一下!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018546 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved