비디오 자습서를 통해 C # 예제를 수행하고 있습니다.이 코드를 계속 살펴 보았지만 코드를 실행하면 "C"를 추가하여 값을 온라인 통화로 만들었습니다 Console.WriteLine("Car's value: {0,C}", myNewCar.DetermineMarketValue());
. 오류가 발생합니다. 처리되지 않은 예외 mscorlib.dll에서 'System.FormatException'유형의 발생 추가 정보 : 입력 문자열이 올바른 형식이 아닙니다.
carValue;
"100.0"을 반환 하는 코드 반환의 마지막 줄을 확인했습니다.
나는 약간 난처하고 건너 뛰고 싶지 않습니다. VB.Net에서 나는 코드 블라인드 가 될 수 있습니다 !!
전체 코드 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimpleClasses
{
class Program
{
static void Main(string[] args)
{
Car myNewCar = new Car();
myNewCar.Make = "Mini";
myNewCar.Model = "Cooper";
myNewCar.Year = 2010;
myNewCar.Color = "Blue";
Console.WriteLine("{0} - {1} - {2}",
myNewCar.Make,
myNewCar.Model,
myNewCar.Color);
//double marketValueOfCar = determineMarketValue(myNewCar);
Console.WriteLine("Car's value: {0,C}", myNewCar.DetermineMarketValue());
Console.ReadLine();
}
private static double determineMarketValue(Car _car)
{
double carValue = 250.00;
//this would usually come from online but this is hardcoded for examples
return carValue;
}
}
class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public string Color { get; set; }
public double DetermineMarketValue()
{
double carValue = 250.00;
if (this.Year > 2015)
carValue = 200.00;
else
carValue = 100.00;
return carValue;
}
}
}
서식이 있어야합니다 {0:C}
(대신을 {0,C}
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다