谁能帮我返回静态列表<>
我有,我想用来存储许多不同类型的列表(float类型,Vector2等的列表)的静态ListHelper类。然后当我想访问某个列表时,我可以调用这个类的方法<>
例如,我有一个名为CalculationHelper的类,我将用它来做一些计算。一旦完成了特定的计算,我将这些值添加到ListHelper中的一个列表中。
但是,如何从这个静态ListHelper类返回值到Game1课程?
这是我的代码来显示我正在尝试做什么。 首先,我称之为CalculationHelper方法做了一些计算,从的Game1
CalculationHelper.ForceIntersections(LineList[i], LineList[i + 1]);
然后在CalculationHelper我做了计算,结果在ListHelper类添加到我的VanishingPoint列表
public static class CalculationHelper
{
public static void ForceIntersections(Line line1,Line line2,List<Sprite> VanishingPointIntersectionList, String greenCirlce)
{
Vector2 intersectionPoint;
// Do some calculations
// Add value to ListHelper
ListHelper.IntersectionPoint = intersectionPoint;
}
}
然后在ListHelper加交点到清单
public static class ListHelper
{
static List<Vector2> VanishingPoint = new List<Vector2>();
static Vector2 intersectionPoint;
public static Vector2 IntersectionPoint
{
get
{
// How do I return the List?
foreach (var value in VanishingPoint)
{
return value; // NOT WORKING
}
}
set
{
intersectionPoint = value;
VanishingPoint.Add(intersectionPoint);
}
}
}
任何人都可以请解释这是如何完成的,也许即使这是st的方式来做到这一点?
为什么一切都是静态的? – Jon 2012-04-21 12:55:39
我使用了静态,所以我不需要非静态方法的对象引用。公众ListHelper会是一个更好的解决方案,你会建议吗? – heyred 2012-04-21 12:58:05