none
HashTable排序问题 RRS feed

  • 问题

  • 将HashTable存放到ArrayList中 为什么HashMap的第一个值的等于第二个数的值,最后一个值为第一值,有什么办法能够解决这种排序方法,
    2010年12月28日 6:05

答案

  • dear
    1.你的问题跟代码里的不同意思,建议您在整理一番,在发问会比较快得到您要的答案
    2.如同我之前回复的,若要排序建议使用SortedList 类别
    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
    • 已建议为答案 eryang 2011年1月4日 6:28
    • 已标记为答案 eryang 2011年1月5日 3:52
    2010年12月29日 2:58

全部回复

  • dear
    1.基本上HashTable是会按照内部演算法自动排序,他不开放排序的,若你要排序可使用SortedList。

    [Edit this entry.] [C#.NET][VB.NET] 一般集合 – Hashtable 集合 類別 建立查詢表 / 搜尋關鍵字
    http://www.dotblogs.com.tw/yc421206/archive/2009/01/24/6932.aspx

    [C#.NET][VB.NET] 一般集合 - SortedList 集合類別 排序
    http://www.dotblogs.com.tw/yc421206/archive/2009/01/24/6933.aspx

    [C#.NET][VB.NET] 一般 / 泛型 Generic Collection 集合型別介紹
    http://www.dotblogs.com.tw/yc421206/archive/2009/01/25/6941.aspx

    2.不过您提到是把HashTable装进ArrayList,不知您是如何实做代码的,请贴上您的代码好认其他人方便诊断
    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
    2010年12月29日 1:16
  •   case "2":
                                            if (Request["radio_" + dr["Exam_Question_Id"].ToString()] != null)
                                            {
                                                listUserQuestion.Add(new ExamOnline.Model.admin.ExamManage.Exam_UserQuestion()
                                                {
                                                    Exam_TestPaperDetail_Id = Convert.ToInt32(dr["Exam_TestPaperDetail_Id"].ToString()),
                                                    Exam_TestPaper_Id = paperId,
                                                    Exam_TestPaperDetail_Score = Convert.ToDecimal(dr["Exam_TestPaperDetail_Score"]),
                                                    Exam_UserQuestion_Evaluate = 1,
                                                    Exam_UserQuestion_Content = Request["radio_" + dr["Exam_Question_Id"].ToString()],
                                                    Exam_UserQuestion_Score = Request["radio_" + dr["Exam_Question_Id"].ToString()].ToString().Equals(dr["Exam_Question_RightAnswer"].ToString()) ? Convert.ToDecimal(dr["Exam_TestPaperDetail_Score"]) : 0
                                                }
                                                );
                                                //错题本
                                                if (!Request["radio_" + dr["Exam_Question_Id"].ToString()].ToString().Equals(dr["Exam_Question_RightAnswer"].ToString()))
                                                {
                                                    listMistake.Add(
                                                        new ExamOnline.Model.admin.ExamManage.Exam_Mistake()
                                                        {
                                                            Exam_Question_Id = int.Parse(dr["Exam_Question_Id"].ToString()),

                                                            Exam_TestPaper_Id = paperId,
                                                            userid = new Model.admin.ExamManage.ProfileUserInfo().intUserID,
                                                            Exam_Mistake_Title = questiontpMap[dr["Exam_QuestionType_id"].ToString()].ToString() + questionSortMap[dr["Exam_Question_Order"].ToString()].ToString(),
                                                            Exam_Question_WrongtAnswer = Request["radio_" + dr["Exam_Question_Id"].ToString()],
                                                            Exam_Mistake_Time = DateTime.Now
                                                        }

                                                    );
                                                }
                                                else
                                                {
                                                    rightCnt++;
                                                }
                                                //总分
                                                UserPaper.Exam_UsePaper_Score += Request["radio_" + dr["Exam_Question_Id"].ToString()].ToString().Equals(dr["Exam_Question_RightAnswer"].ToString()) ? Convert.ToDecimal(dr["Exam_TestPaperDetail_Score"]) : 0;
                                            }
                                            else
                                            {
                                                listUserQuestion.Add(new ExamOnline.Model.admin.ExamManage.Exam_UserQuestion()
                                                {
                                                    Exam_TestPaperDetail_Id = Convert.ToInt32(dr["Exam_TestPaperDetail_Id"].ToString()),
                                                    Exam_TestPaper_Id = paperId,
                                                    Exam_TestPaperDetail_Score = Convert.ToDecimal(dr["Exam_TestPaperDetail_Score"]),
                                                    Exam_UserQuestion_Evaluate = 1,
                                                    Exam_UserQuestion_Content = "",
                                                    Exam_UserQuestion_Score = 0
                                                });
                                                //错题本
                                                listMistake.Add(
                                                        new ExamOnline.Model.admin.ExamManage.Exam_Mistake()
                                                        {
                                                            Exam_Question_Id = int.Parse(dr["Exam_Question_Id"].ToString()),
                                                            Exam_TestPaper_Id = paperId,
                                                            userid = new Model.admin.ExamManage.ProfileUserInfo().intUserID,
                                                            Exam_Mistake_Title = questiontpMap[dr["Exam_QuestionType_id"].ToString()].ToString() + questionSortMap[dr["Exam_Question_Order"].ToString()].ToString(),
                                                            Exam_Question_WrongtAnswer = "",
                                                            Exam_Mistake_Time = DateTime.Now
                                                        }
                                                    );
                                            }
                                            totalCnt++;
                                            break;



    我想把里面的HashTable 使用ArrayList 进行替换 从而 使用ArrayList 的Sort排序  根据 进来的数据顺序进行排序
    2010年12月29日 2:08
  • dear
    1.你的问题跟代码里的不同意思,建议您在整理一番,在发问会比较快得到您要的答案
    2.如同我之前回复的,若要排序建议使用SortedList 类别
    秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/
    • 已建议为答案 eryang 2011年1月4日 6:28
    • 已标记为答案 eryang 2011年1月5日 3:52
    2010年12月29日 2:58