moTaro
Буљаш
- Член од
- 17 ноември 2005
- Мислења
- 1.476
- Поени од реакции
- 11
using System;
using System.Collections.Generic;
public class Temperature : IComparable<Temperature>
{
public int CompareTo(Temperature other)
{
return m_value.CompareTo(other.m_value);
}
protected double m_value = 0.0;
public double Celsius
{
get
{
return m_value - 273.15;
}
}
public double Kelvin
{
get
{
return m_value;
}
set
{
if (value < 0.0)
{
throw new ArgumentException("Temperature cannot be less than absolute zero.");
}
else
{
m_value = value;
}
}
}
public Temperature(double degreesKelvin)
{
this.Kelvin = degreesKelvin;
}
}
public class Example
{
public static void Main()
{
SortedList<Temperature, string> temps =
new SortedList<Temperature, string>();
temps.Add(new Temperature(2017.15), "Boiling point of Lead");
temps.Add(new Temperature(0), "Absolute zero");
temps.Add(new Temperature(273.15), "Freezing point of water");
temps.Add(new Temperature(5100.15), "Boiling point of Carbon");
temps.Add(new Temperature(373.15), "Boiling point of water");
temps.Add(new Temperature(600.65), "Melting point of Lead");
foreach( KeyValuePair<Temperature, string> kvp in temps )
{
Console.WriteLine("{0} is {1} degrees Celsius.", kvp.Value, kvp.Key.Celsius);
}
}
}
не е тоа филозофско прашање.
еве ти одговор.
using System.Collections.Generic;
public class Temperature : IComparable<Temperature>
{
public int CompareTo(Temperature other)
{
return m_value.CompareTo(other.m_value);
}
protected double m_value = 0.0;
public double Celsius
{
get
{
return m_value - 273.15;
}
}
public double Kelvin
{
get
{
return m_value;
}
set
{
if (value < 0.0)
{
throw new ArgumentException("Temperature cannot be less than absolute zero.");
}
else
{
m_value = value;
}
}
}
public Temperature(double degreesKelvin)
{
this.Kelvin = degreesKelvin;
}
}
public class Example
{
public static void Main()
{
SortedList<Temperature, string> temps =
new SortedList<Temperature, string>();
temps.Add(new Temperature(2017.15), "Boiling point of Lead");
temps.Add(new Temperature(0), "Absolute zero");
temps.Add(new Temperature(273.15), "Freezing point of water");
temps.Add(new Temperature(5100.15), "Boiling point of Carbon");
temps.Add(new Temperature(373.15), "Boiling point of water");
temps.Add(new Temperature(600.65), "Melting point of Lead");
foreach( KeyValuePair<Temperature, string> kvp in temps )
{
Console.WriteLine("{0} is {1} degrees Celsius.", kvp.Value, kvp.Key.Celsius);
}
}
}
не е тоа филозофско прашање.
еве ти одговор.