Additional options in the XNA app for Windows Phone XNA

Is it possible to use optional parameters (and other purely syntactic functions of C # 4.0) in Windows Phone XNA applications?

I read and heard conflicting information about this. In the advanced build settings for my application, the language version is set to C # 3.0 (C # 4.0 is not available in the Version language drop-down list). Is 3.0 the official version of C # that will initially be used to develop Windows Phone?

Do I really not think that the features of C # 4.0 will be available at all?

+4
source share
4 answers

Under Silverlight and XNA flair lies some version of the compact .NET 3.x framework (3.7?). Compared to Windows Phone 7 in relation to the rest of the market, this is far from the case that it is unlikely that the compact .NET 4.0 infrastructure will be implemented (afaik does not exist yet) or any other important architectural changes necessary to support C # 4.0.

+4
source

I found that optional parameters work correctly in Silverlight, but not in XNA. I used #if stuff to get around this in general code as follows:

#if !SILVERLIGHT public SomeClass ( ) : this (null) { } public SomeClass(object someParam) #else public SomeClass(object someParam = null) #endif { m_someParam = someParam; } 

But this touch is ugly. I also noticed that the Add Links dialog box from PowerPoint Power Pack does not work with XNA projects, indicating that something suspicious is happening with XNA projects. [As a note, I can deploy and debug Silverlight applications for the emulator through VS, but not XNA applications]

+1
source

Best solution: use function overloading.

Example (causes errors):

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

...

Decision:

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

...

Super lightweight. Done.

+1
source

I'm not sure that you can use optional parameters with Xna (I never had a desire), but you can do what you're talking about.

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

The link above says your language version is set by default, not C # 3.0. It seems you were on the right track.

0
source

Source: https://habr.com/ru/post/1313964/


All Articles