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車載重大");
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类型?
时还是别用tostring