2015-09-13 169 views
-1

我有汽車租賃計劃方面的工作,但是我有租賃類問題。 如果我需要檢查,這輛車在陣列中已經租了嗎?我該怎麼辦。 如果有申報汽車股票的數組是這樣的:c上的汽車租賃編程#

static void Main(string[] args) 
    { 

     Car[] car; 
     car = new Car[5]; 
     Car[] car; 
     car = new Car[5]; 
     car[0] = new Car("Number", "Brand", "Model", Kilometers); 
     and go on till car[4] 

我我應該做的檢查車?

+0

以面向對象的方式思考。當你說汽車租賃或汽車沒有租用。這是「是一種」關係。現在你應該閱讀「是一個」和「有一個」關係。 –

+0

更新一個汽車對象的prooerty更改後,你需要實現INotifyPropertyChanged接口 –

回答

1

只是一個BooleanIsRent屬性添加到您Car類,並且每次有人租了車,改變它的價值,以。財產以後這樣的:

if(car[/here put the index].IsRent==true)//car is not in rent,allow to rent. 
{ 
    car[/here put the index].IsRent=false; 
     //rent the car. 
    } 


public bool IsRentM 
{ 
    get { return IsRent; } 
    set { IsRent = value; } 


} 

古德勒克。

+0

什麼得到{...}和集{...}我應該在屬性中使用。 – Isafe

+0

@Isafe補充說。如果我幫你,請標記我的答案,請:) – Slashy

+0

非常感謝@Slashy它是非常有用的 – Isafe