| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1217 人关注过本帖
标题:[求助]C#入门经典 案例分析1
只看楼主 加入收藏
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
 问题点数:0 回复次数:4 
[求助]C#入门经典 案例分析1

按书上说的,谁弄过??

我CLASS1

using System; using System.Data; using System.IO; using System.Xml;

namespace PollC { /// <summary> /// Class1 的摘要说明。 /// </summary> class Class1 { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main(string[] args) { Poll myPoll = Poll.Current(); //Console.WriteLine(myPoll.Question); DisplayPoll(myPoll); myPoll.Vote(2); Console.WriteLine("Vote registered against " + myPoll.Answers[2]); DisplayPoll(myPoll); // // TOD 在此处添加代码以启动应用程序 // } private static void DisplayPoll(Poll aPoll) { Console.WriteLine("========Poll========"); Console.WriteLine(aPoll.Question); for(int i=1;i<=(aPoll.AnswerCount);i++) { Console.WriteLine(aPoll.Answers[i] + ":"); Console.WriteLine(aPoll.Votes[i] + "votes"); } Console.WriteLine("===================="); } } }

创建了类Poll.cs

using System; using System.Data; using System.IO; using System.Xml;

namespace Polling { /// <summary> /// Poll 的摘要说明。 /// </summary> public class Poll { private int[] myVotes; private string[] myAnswers; private string myQuestion; private int myAnswerCount; private string myFilename;

public static Poll Current() { Poll myPoll = new Poll(@"C:\Inetpub\wwwroot\polls.xml"); return myPoll; } private Poll(string filename) { myFilename = filename; DataSet myDataSet = new DataSet(); FileStream fsReadXml = new FileStream(filename,FileMode.Open); XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml); myDataSet.ReadXml(myXmlReader); myXmlReader.Close(); myAnswerCount = myDataSet.Tables[1].Rows.Count; myQuestion = myDataSet.Tables[0].Rows[0].ItemArray[1].ToString(); myAnswers = new string[myAnswerCount+1]; string answer; for(int i=0;i<myAnswerCount;i++) { answer = myDataSet.Tables[1].Rows[i].ItemArray[0].ToString(); myAnswers[i+1]=answer; } myVotes = new int[myAnswerCount+1]; string votes; for(int i=0;i<myAnswerCount;i++) { votes = myDataSet.Tables[1].Rows[i].ItemArray[1].ToString(); myVotes[i+1] = int.Parse(votes); } } public void Vote(int answer) { if(answer == 0 || answer>myAnswerCount) { throw(new Exception("Invalid choice of answe.")); } myVotes[answer]++; DataSet myDataSet = new DataSet(); FileStream fsReadXml = new FileStream(myFilename,System.IO.FileMode.Open); XmlTextReader myXmlReader = new System.Xml.XmlTextReader(fsReadXml); myDataSet.ReadXml(myXmlReader); myXmlReader.Close(); string votes = myDataSet.Tables[1].Rows[answer-1].ItemArray[1].ToString(); int votesInt = int.Parse(votes); DataRow myVotesRow = myDataSet.Tables[1].Rows[answer-1]; myVotesRow["Votes"] = (votesInt+1).ToString(); StreamWriter myStream = new StreamWriter(myFilename); myDataSet.WriteXml(myStream,XmlWriteMode.IgnoreSchema); myStream.Close(); } public int AnswerCount { get { return myAnswerCount; } } public string Question { get { return myQuestion; } } public string[] Answers { get { return myAnswers; } } public int[] Votes { get { return myVotes; } } public Poll() { // // TOD 在此处添加构造函数逻辑 // } } }

运行的时候不能通过

提示:

C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\PollC\Class1.cs(29): 找不到类型或命名空间名称“Poll”(是否缺少 using 指令或程序集引用?)

谁懂的告诉一下~~~~~~~~

搜索更多相关主题的帖子: 入门 经典 
2005-05-09 22:01
夏色沙漏
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2004-11-12
收藏
得分:0 
各位大哥帮忙下,小弟真不懂哪里问题,有弄过的人帮解答下
2005-05-09 22:04
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
命名空间不同,

namespace Polling 改为namespace PollC

2005-05-09 23:57
论坛元老
Rank: 1
等 级:新手上路
帖 子:812
专家分:0
注 册:2008-3-31
收藏
得分:0 
新手,学习中,支持
2008-04-02 16:58
爱得心好累
Rank: 2
等 级:论坛游民
帖 子:60
专家分:24
注 册:2009-11-22
收藏
得分:0 
怎么到这了..

[url]http://shishangxiaowu277.[/url]出售时尚女装,话费、QQ、以及游戏充值。价格实惠
2010-01-24 21:26
快速回复:[求助]C#入门经典 案例分析1
数据加载中...
 
   



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

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