2014-07-13 1 views
0

현재 C#을 배우고 있으며 클래스 상속에 대해 머리를 써보고 콘솔에 줄을 표시하는 코드를 작성했지만 이 게시물 제목의 오류와 관련된 문제가 있습니다."System.FormatException"형식의 처리되지 않은 예외 입력 문자열의 형식이 올바르지 않습니다.

하위 클래스 PC에서 string.format 줄에 오류가 발생했습니다. 나는 그것이 지나가고있는 타입들과 관련이 있다고 가정하고 있지만, 지금까지 시도한 모든 것은 작동하지 않습니다. 모든 교육은 다음 단계로 넘어 가기 전에 모든 것을 이해하고 싶습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace ClassInheritance 
{ 
    class Program 
    { 
    static void Main(string[] args) 
    { 
     PC myPC = new PC(); 

     myPC.casetype = "Black SuperCool"; 
     myPC.contract = true; 
     myPC.dateadded = DateTime.Now; 
     myPC.id = 1; 
     myPC.type = "Small form factor"; 
     printEquipmentDetails(myPC); 

     Console.ReadLine(); 
    } 

    private static void printEquipmentDetails(Equipment Equipment) 
    { 
     Console.WriteLine("Details: {0}", Equipment.DisplayEquipment()); 
    } 
} 

abstract class Equipment 
{ 
    public int id { get; set; } 
    public string type { get; set; } 
    public bool contract { get; set; } 
    public DateTime dateadded { get; set; } 

    public abstract string DisplayEquipment(); 
} 

class PC : Equipment 
{ 
    public string casetype { get; set; } 

    public override string DisplayEquipment() 
    { 
     return String.Format("(0} - {1} - {2} - {3} - {4}", this.id, this.type, this.contract.ToString(), this.dateadded.ToShortDateString(), this.casetype); 
    } 
} 

class Laptop : Equipment 
{ 
    public string batterylife { get; set; } 

    public override string DisplayEquipment() 
    { 
     return String.Format("(0} - {1} - {2} - {3} - {4}", this.id, this.type, this.contract, this.dateadded, this.batterylife); 
    } 
} 
} 

답변

0

당신의 return String.Format("(0} - {1} - {2} - {3} - {4}"... 라인 {(를 교체합니다.

을 그래서
return String.Format("(0} - {1} - {2} - {3} - {4}"...

return String.Format("그 것이었다 {0} - {1} - {2} - {3} - {4}"...

+0

! 감사합니다 것 . 인텔리 센스 정상적으로 나는 그러한 멍청한 실수를 저지른다. – Trinitrotoluene

관련 문제