誰能幫我返回靜態列表<>
我有,我想用來存儲許多不同類型的列表(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