C# List<T>.Find

Started by
33 comments, last by Anthracis 11 years, 7 months ago



public T GetObject<T>(int objectId) where T: EngineObject
{
if (m_objectInstances.ContainsKey(typeof(T)))
{
List<EngineObject> objectList = m_objectInstances[typeof(T)];
return (T) objectList.Find(delegate(EngineObject obj) { return obj.ID == objectId; });
}
return default(T);
}


Or


public T GetObject<T>(int objectId) where T: EngineObject
{
if (m_objectInstances.ContainsKey(typeof(T)))
{
List<EngineObject> objectList = m_objectInstances[typeof(T)];
return (T) objectList.Find(obj => obj.ID == objectId);
}
return default(T);
}



Thanks for testing that out!

I've found that if I supply the EngineObject type in the function prototype, as you suggested :


public T GetObject<T>(int objectId) where T: EngineObject


it compiles without any errors on x86. I still get the same compile error on the Xenon platform, but I'm halfway there now smile.png
Advertisement
Im having some problems converting the project here, and I'm at my work pc, so can't really check the other case :P Weird that this works differently on a different platform.

Im having some problems converting the project here, and I'm at my work pc, so can't really check the other case tongue.png Weird that this works differently on a different platform.

Yeah quite strange... makes more sense that it would be a platform specific problem though, couldn't fathom why it wasn't compiling on x86 smile.png

Here's the Xenon project file http://www.2shared.com/file/GWlPZyxm/Engine.html
Now, someone with more knowledge of building xna projects for xbox could probably correct me here, but I noticed the Xenon project uses .NET v2.0. So while the xna assemblies are version 4, the rest of the .net assemblies are version 2.0, and in that version, the List<> doesn't have a the Find() function. That's Probably because the xbox 360 doesn't support anything higher than that version. So if you want the game to work on xbox, you will have to write the game using stuff that exists in .net 2.0 and below only. Someone please correct me if I'm wrong smile.png

As a side note: it is interesting that linq works there, since it was introduced in .net 3.5 iirc, but looking at the assembly version says its also 2.0... and reading up a bit it seems like xbox supports it.

Now, someone with more knowledge of building xna projects for xbox could probably correct me here, but I noticed the Xenon project uses .NET v2.0. So while the xna assemblies are version 4, the rest of the .net assemblies are version 2.0, and in that version, the List<> doesn't have a the Find() function. That's Probably because the xbox 360 doesn't support anything higher than that version. So if you want the game to work on xbox, you will have to write the game using stuff that exists in .net 2.0 and below only. Someone please correct me if I'm wrong smile.png

As a side note: it is interesting that linq works there, since it was introduced in .net 3.5 iirc, but looking at the assembly version says its also 2.0... and reading up a bit it seems like xbox supports it.


Oh nice catch! Thanks for your help :)

Now, someone with more knowledge of building xna projects for xbox could probably correct me here, but I noticed the Xenon project uses .NET v2.0. So while the xna assemblies are version 4, the rest of the .net assemblies are version 2.0, and in that version, the List<> doesn't have a the Find() function. That's Probably because the xbox 360 doesn't support anything higher than that version. So if you want the game to work on xbox, you will have to write the game using stuff that exists in .net 2.0 and below only. Someone please correct me if I'm wrong smile.png

As a side note: it is interesting that linq works there, since it was introduced in .net 3.5 iirc, but looking at the assembly version says its also 2.0... and reading up a bit it seems like xbox supports it.


.net-Framework versions 2.0 to 3.5 use the runtime version 2.0.
Features like Linq are only framework additions that are compiled to byte code running on a 2.0 runtime.

With Frameword version 4.0 a new runtime was introduced.
So assuming that the XBox uses a 2.0 runtime all features available up to Framework 3.5 should be available.

Edit: reformulated the post

This topic is closed to new replies.

Advertisement