これは、メッセージが表示される C# クラスの更新バージョンです。
到達不能なコードが検出されました: DateTime.Now.Ticks;
他のすべては問題ないようです。私の間違いはどこですか?
using System;
using System.Globalization;
namespace domain
{
public class Request : Unique
{
private DateTime dateBooked_Renamed;
private DateTime dateSignedIn ;
private DateTime dateSignedOut ;
private bool arrived_Renamed = false;
private bool paid_Renamed = false;
private Hotel hotel_Renamed;
private Employee employee_Renamed;
private int numberOfNights;
public Request(Hotel hotel, Employee employee, string dateBooked, string dateArrived, int numberOfNights)
: base()
{
this.hotel_Renamed = hotel;
this.employee_Renamed = employee;
this.numberOfNights = numberOfNights;
try
{
DateTime.ParseExact(dateBooked, "dd/MM/yyyy", CultureInfo.InvariantCulture);
this.dateBooked_Renamed = DateTime.ParseExact(dateBooked, "dd/MM/yyyy", CultureInfo.InvariantCulture);
this.dateSignedIn = DateTime.ParseExact(dateArrived, "dd/MM/yyyy", CultureInfo.InvariantCulture);
}
catch (FormatException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
}
public virtual bool checkout(double money, string date)
{
try
{
dateCheckedOut = DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
}
catch (FormatException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
if (money >= price())
{
paid = true;
}
else
{
paid = false;
}
return paid_Renamed;
}
public virtual int days()
{
long tNow = dateSignedOut != null ? dateSignedOut.Ticks : DateTime.Now.Ticks;
long tThen = arrived ? dateArrived.Ticks : tNow;
long diff = tNow - tThen;
long secondInMillis = 1000;
long minuteInMillis = secondInMillis * 60;
long hourInMillis = minuteInMillis * 60;
long dayInMillis = hourInMillis * 24;
long yearInMillis = dayInMillis * 365;
diff = diff % yearInMillis;
long elapsedDays = diff / dayInMillis;
return (int)elapsedDays;
}
public virtual Hotel hotel
{
get
{
return hotel_Renamed;
}
set
{
this.hotel_Renamed = value;
}
}
public virtual DateTime dateArrived
{
get
{
return dateSignedIn;
}
set
{
this.dateSignedIn = value;
}
}
public virtual DateTime dateBooked
{
get
{
return dateBooked_Renamed;
}
set
{
this.dateBooked_Renamed = value;
}
}
public virtual DateTime dateCheckedOut
{
get
{
return dateSignedOut;
}
set
{
this.dateSignedOut = value;
}
}
public virtual Employee employee
{
get
{
return employee_Renamed;
}
set
{
this.employee_Renamed = value;
}
}
public virtual bool arrived
{
get
{
return arrived_Renamed;
}
set
{
this.arrived_Renamed = value;
}
}
public virtual bool paid
{
get
{
return paid_Renamed;
}
set
{
this.paid_Renamed = value;
}
}
public virtual double price()
{
// The total cost of the stay...
double price = days() * employee_Renamed.type.price;
if (hotel_Renamed.premium)
{
return price - (0.2 * price);
}
else
{
return price;
}
}
public virtual bool hasArrivalDate(string date)
{
try
{
DateTime d = DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
Console.WriteLine("Comparing " + d + " with " + dateSignedIn + " = " + dateSignedIn.ToString("dd/MM/yyyy").Equals(d.ToString("dd/MM/yyyy")));
return dateSignedIn.ToString().Equals(d.ToString());
}
catch (FormatException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
return false;
}
}
}
}