| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 635 人关注过本帖
标题:各位大哥,写的代码不能调试,请帮帮忙
只看楼主 加入收藏
云鹤
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2011-6-24
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:4 
各位大哥,写的代码不能调试,请帮帮忙
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace jihe
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Racer> racers = new List<Racer>(new Racer[]
                {
                    new Racer("ochen","Rindt","Austria",6),
                    new Racer("Ayrton","Senan","Brazil",41),
                });

            
            Racer[] racer1 =
            {

                   new Racer("Graham","Hill","UK",14),
                   new Racer("Emerson", "Fittipalde", "Brazil", 14),
                   new Racer("Mario","Andretti","USA", 12),
                   new Racer("Michael","Schumacher","Germany",91),
                   new Racer("Mika","Hakkinen","Finland",20),
                    new Racer("Nile","Lauda","Austria",25),
                   new Racer("Alian","Prost","France",51),
            };
            racers.AddRange(racer1);
            racers.Insert(3, new Racer("Phil", "Hill", "USA", 3));

            for (int i = 0; i < racers.Count; i++)
            {
                Console.WriteLine(racers[i]);
            }
         
            }
        }
      


    public class Racer : IComparable<Racer>,IFormattable
    {
        private string firstname;
        private string lastname;
        private string country;
        private int wins;

        public Racer() : this(String.Empty, string.Empty, string.Empty) { }

        public Racer(string firstname, string lastname, string country) : this(firstname, lastname, country, 0) { }

        public Racer(string firstname, string lastname, string country, int wins)
        {
            this.firstname = firstname;
            this.lastname = lastname;
            this.country = country;
            this.wins = wins;
        }

        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public string Country { get; set; }
        public string Wins { get; set; }

        public override string ToString()
        {
            return string.Format("{0} {1}", Firstname, Lastname);
        }

        public string ToString(string format, IFormatProvider formatProvider)
        {
            switch (format.ToUpper())
            {
                case null:
                case "N":
                    return ToString();
                case "F":
                    return Firstname;
                case "L":
                    return Lastname;
                case "W":
                    return string.Format("{0},Wis{1}", ToString(), Wins);
                case "A":
                    return string.Format("{0},{1} Wins {2}", ToString(), Country, Wins);
                default:
                    throw new FormatException(string.Format(formatProvider, "Format {0} is not supported", format));
            }
        }

        public string ToString(string format)
        {
            return ToString(format, null);

        }
        public int CompareTo(Racer other)
        {

            int compare = this.(other.Lastname);
            if (compare == 0)
                return this.(other.Firstname);
            return compare;
        }

        
        
        
        }

}


[ 本帖最后由 云鹤 于 2011-7-8 15:33 编辑 ]
搜索更多相关主题的帖子: class 大哥 
2011-07-07 21:12
ai0_0jun
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:32
专家分:145
注 册:2011-6-29
收藏
得分:3 
要是一闪而过的话,就加上 Console.ReadLine() 停止住
2011-07-08 09:49
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:3 
不能调试?为什么?出什么问题了?
2011-07-08 09:58
云鹤
Rank: 1
等 级:新手上路
帖 子:7
专家分:2
注 册:2011-6-24
收藏
得分:0 

未处理的异常:  System.NullReferenceException: 未将对象引用设置到对象的实例。
   在 jihe.Racer.ToString(String format, IFormatProvider formatProvider) 位置 D:
\My Documents\Visual Studio 2008\Projects\jihe\jihe\Class5.cs:行号 75
   (Object value)
   (Object value)
   在 System.Console.WriteLine(Object value)
   在 jihe.Program.Main(String[] args) 位置 D:\My Documents\Visual Studio 2008\P
rojects\jihe\jihe\Class5.cs:行号 36
请按任意键继续. . .
2011-07-08 15:32
girl0001
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:118
注 册:2010-7-17
收藏
得分:3 
public string ToString(string format, IFormatProvider formatProvider)
        {
            switch (format.ToUpper())
            {
                case null:
                case "N":
                    return ToString();
                case "F":
                    return Firstname;
                case "L":
                    return Lastname;
                case "W":
                    return string.Format("{0},Wis{1}", ToString(), Wins);
                case "A":
                    return string.Format("{0},{1} Wins {2}", ToString(), Country, Wins);
                default:
                    throw new FormatException(string.Format(formatProvider, "Format {0} is not supported", format));
            }
        }

参数format为null.
2011-07-09 18:46
快速回复:各位大哥,写的代码不能调试,请帮帮忙
数据加载中...
 
   



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

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