C#编程核心:类与对象的深入探索
1. 数字猜谜游戏实践
在编程学习中,实践是掌握知识的关键。这里有两个有趣的数字猜谜游戏程序,能帮助我们更好地理解C#编程。
1.1 命令行版猜谜程序(Guess.cs)
以下是该程序的代码:
// Guess.cs - Pick a Number
//-------------------------------------------------------
using System;
using System.Drawing;
using System.Text;
public class Guess
{
private static int getRandomNumber( int nbr )
{
if ( nbr > 0 )
{
Random Rnd = new Random();
return (Rnd.Next(0, nbr));
}
else
{
return 0;
}
}
private static void WriteStats(string Guess, int nbr, string err )
{
Console.WriteLine("\n==============================");
Console.WriteLine("Current Guess: {0}", G
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



