4

Windows Phone XNA アプリケーションでオプションのパラメーター (およびその他の純粋に構文的な C# 4.0 機能) を使用することは可能ですか?

これについて相反する情報を読んだり聞いたりしました。アプリケーションの [高度なビルド設定] で、[言語バージョン] が C# 3.0 に設定されています ([言語バージョン] ドロップダウン リストでC# 4.0 を使用できません)。3.0 は、最初に Windows Phone の開発に使用される「公式」の C# バージョンですか?

C# 4.0 の機能がまったく利用可能になると期待するのはばかげているでしょうか?

4

4 に答える 4

4

Silverlight と XNA の才能の下には、.NET 3.x (3.7?) コンパクト フレームワークのいくつかのバージョンがあります。Windows Phone 7 が市場の残りの部分に比べてはるかに遅れている限り、.NET 4.0 コンパクト フレームワークが挿入される可能性は低く (Afaik はまだ存在しません)、サポートに必要なその他の主要なアーキテクチャの変更はありません。 C# 4.0。

于 2010-06-26T18:48:04.643 に答える
1

最善の解決策: 関数のオーバーロードを利用します。

例 (エラーの原因):

public void RenderRadius(SpriteBatch spriteBatch, Entity entity, float radiusOverride = -1)

...

解決:

public void RenderRadius(SpriteBatch spriteBatch, Entity entity){ RenderRadius(spriteBatch, entity, -1); }
public void RenderRadius(SpriteBatch spriteBatch, Entity entity, float radiusOverride)

...

超簡単。終わり。

于 2012-03-18T05:38:51.300 に答える
1

I have found that Optional Parameters work properly in Silverlight but not in XNA. I have been using the #if stuff to get around this in shared code as follows:

#if !SILVERLIGHT
public SomeClass ( ) : this (null)
{
}

public SomeClass(object someParam)

#else

public SomeClass(object someParam = null)

#endif
{
    m_someParam = someParam;
}

But that is a touch ugly. I have also noticed the Add References dialog from the Productivity Power Pack doesn't work with XNA projects, indicating something fishy is going on with XNA projects. [As a side note, I can deploy and debug Silverlight apps to the emulator via VS but NOT XNA apps]

于 2011-05-19T03:30:40.570 に答える
0

オプションのパラメーターを Xna で使用できるかどうかはわかりませんが (そうしたいと思ったことは一度もありません)、あなたが話していることはできます。

http://xboxforums.create.msdn.com/forums/p/54007/515654.aspx

上記のリンクでは、言語バージョンを C# 3.0 ではなくデフォルトに設定するように指示されています。あなたは正しい軌道に乗っていたようです。

于 2013-02-19T04:32:16.070 に答える