1

C# XNA Xbox, in this case optional parameters are not optional

Thanks to help from the above question optional parameters are now working, or at least appear as if they should work.

However I'm now stuck on HashSets and Tuples, that don't appear to be available either.

I could write my own version of both classes. Tuple from scratch and HashSet using a Dictonary (possibly). However I'd rather keep to using the standard ones.

If these classes exist in the PC verstion of the library, then can I copy and paste them from the PC C# library into my own code?

Using "Go To Definition" results in "HashSet [from metadata]" and is C++ header file like in that it shows the classes interface but no implementation.

Continued here: stackoverflow.com/questions/10246572/c-sharp-hashset2-to-work-exactly-like-the-standard-c-sharp-hashset-not-compilin

Community
  • 1
  • 1
alan2here
  • 3,223
  • 6
  • 37
  • 62
  • You cannot see the implementation because Microsoft does not release debug symbols with XNA's binaries. Otherwise, they'd be giving all of XNA's source code away. You can see exactly the same your code will see: names, types, attributes... but no code and no private members. – Elideb Apr 02 '12 at 09:34

2 Answers2

2

There both very basic data structures you can just make your own.

Here is a HashSet.

And Here is a Tuple just add more items as needed.

public class Tuple<T1, T2> 
{ 
   public T1 Item1 { get; set; } 
   public T2 Item2 { get; set; } 

   public Tuple(T1 item1, T2 item2) 
   { 
      Item1 = item1; 
      Item2 = item2; 
   } 
} 
ClassicThunder
  • 1,896
  • 16
  • 25
  • The HashSet implementation linked to above means storing a lot of unused values, presumably some of this can be negated by using bool instead of the UInt16s they've used? Are the built in Tuples implemented like this? "public T1 Item1 {get; set;}" looks like a definition for a property, where is the data stored? Also, copying the original HashSet definition seems like it should perform better than creating another layer of abstraction using Dictionary. I wouldn't normally mind but it could be used in an unusually performance sensitive context. – alan2here Apr 01 '12 at 19:02
  • 1
    HashSet is always storing a lot of unused values, so if space is so important build something else, using dictionary that also stores value for a key will make it just slightly worse. `{get;set;}` are [auto-implemented properties](http://msdn.microsoft.com/en-us/library/bb384054.aspx). – Alexei Levenkov Apr 01 '12 at 19:06
  • Thanks, auto-implemented properties will come in useful. ClassicThunder's Tuple appears to be pleasently more mutable than vanilla C# tuples. Dosn't look like it works with equality, presumably I'd have to implement that, as well as other things I havn't yet thought of. I hope the HashSet turns out to have a sufficiently similar interface not to break things. I don't see why I can't copy the vanilla ones. What happens if I add a new referance to the project using the Solution Explorer "Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Core.dll"? – alan2here Apr 01 '12 at 19:29
1

No, you cannot get the PC binaries and use them on the Xbox. They are compiled for different hardware and an XNA X360 project will refuse to use PC dlls.

There are probably several implementations of those classes around. I'm pretty sure many physics and engine projects in CodePlex have them already, and picking them is perfectly legal (although showing recognition is always recommended).

Elideb
  • 11,660
  • 1
  • 16
  • 16