0
當我嘗試將變量elapseseconds轉換爲ToInt16和ToInt64時出現錯誤。Timespan不能Convert.ToInt16(elapsedSeconds))並且不能Convert.ToInt64(elapsedSeconds))錯誤Unity C#
TimeSpan cTime = new TimeSpan (0, 0, 0, Convert.ToInt16(elapsedSeconds));
得到了一個錯誤:
OverflowException: Value is greater than Int16.MaxValue or less than Int16.MinValue
System.Convert.ToInt16 (Int64 value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System/Convert.cs:1093)
margaretSellTimer.OnResumeSession() (at Assets/script/margaretShop/margaretSellTimer.cs:148)
margaretSellTimer.Awake() (at Assets/script/margaretShop/margaretSellTimer.cs:28)
,也是我嘗試改變線路是這樣的:
TimeSpan cTime = new TimeSpan (0, 0, 0, Convert.ToInt64(elapsedSeconds));
這也得到了一個錯誤:
Assets/script/margaretShop/margaretSellTimer.cs(148,89): error CS1502: The best overloaded method match for `System.TimeSpan.TimeSpan(int, int, int, int)' has some invalid arguments
Assets/script/margaretShop/margaretSellTimer.cs(148,89): error CS1503: Argument `#4' cannot convert `long' expression to type `int'
我看到的是elapsedSeconds是對大v ALUE,所以我儘量用ToInt64(長),但不能像被轉換..
其實我從CTIME想是象下面這樣:
Seconds = cTime.Seconds;
Minutes = cTime.Minutes;
Hours = cTime.Hours;
days = cTime.Days;
任何想法?
感謝
什麼類型'elapsedSeconds'和價值持有呢? – lokusking
它很長elapsedSeconds = Convert.ToInt64(timestamp) - oldTimestamp; –