Re: [c#]回傳型態為物件,回傳值為null
※ 引述《mygame.bbs@bbs.ccns.ncku.edu.tw (逛逛)》之銘言:
: public RectangleF GetCollisionMBR()
: {
: //...
: return bCollisionMBRExists ? rfCollisionBoundingBox : null;
: } ↑ ↑
: bool RectangleF
: 跑出錯誤
: Type of conditional expression cannot be determined because there is no
: implicit conversion between 'System.Drawing.RectangleF' and '<null>'
: 請問這裡要怎麼改?
: 感謝大德!
RectangleF是struct而不是object, 因此請用RectangleF.Empty代替.
就像用System.IntPtr時用IntPtr.Zero一樣, struct的話很多時候
都不是nullable type, 而需要用特定的member表示「非正常」的值...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 202.134.126.84
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章