RT

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace _1103
    {
        public class Vehicle
        {
            private double _weight;        public double Weight
            {
                get { return _weight; }
                set { _weight = value; }
            }
            private int _count;        public int Count
            {
                get { return _count; }
                set { _count = value; }
            }
            public Vehicle()
            {
     
            }
            public Vehicle(double weight,int count)
            {
                _count = count;
                _weight = weight;
            }
        }
    }
       using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace _1103
    {
        class Program
        {
            static void Main(string[] args)
            {
                Vehicle p = new Vehicle();
                Console.WriteLine(p.Weight.ToString() +p.Count.ToString());
                Vehicle p1 = new Vehicle(120.0, 4);
                Console.WriteLine("p1车的载重:"+p1.Weight.ToString()    +"p1车的车轮:"+ p1.Count.ToString());
                Vehicle p2 = new Vehicle(111,6);
                Console.WriteLine("p2车的载重:"+p2.Weight.ToString()    +"p2车的车轮:"+p2.Count.ToString());
                if (p1.Weight > p2.Weight)
                {
                    Console.WriteLine("p1車載重大");
                }
                else
                    Console.WriteLine("p2車載重大");
                
            }
        }
    }
              
    ps: Console.WriteLine("p1车的载重:"+p1.Weight.ToString()    +"p1车的车轮:"+ p1.Count.ToString());
                Vehicle p2 = new Vehicle(111,6);
                Console.WriteLine("p2车的载重:"+p2.Weight.ToString()    +"p2车的车轮:"+p2.Count.ToString());为什么要转换成string类型?
      

  2.   

    因为你p1 p2定义的不是string 类型。 而 Console.WriteLine()的内容一定要是字符串类型的 所以 要转换下。
      

  3.   

    convert.toString 与 Tostring 是不同的,Tostring里面没try catch. 在数据库取数据时,以防null
    时还是别用tostring