사람이 나에게정적 목록을 반환 <>
도와주세요 수 나는리스트의 다른 유형 (float 형, Vector2 등의 목록)의 수를 저장하는 데 사용할 정적 ListHelper 클래스가 있습니다. 그런 다음 특정 클래스에 액세스하려는 경우이 클래스의 메서드를 호출 할 수 있습니다.
예를 들어 CalculationHelper라는 클래스를 사용하여 일부 계산을 수행합니다. 특정 계산이 완료되면 ListHelper의 내 목록 중 하나에 값을 추가합니다.
하지만이 정적 ListHelper 클래스의 값을 어떻게 반환합니까? Game1 클래스?
다음은 내가하려는 일을 보여주는 코드입니다. 첫째, 나는 GAME1
에서 다음 CalculationHelper에 내가 계산 할CalculationHelper.ForceIntersections(LineList[i], LineList[i + 1]);
을 몇 가지 계산을하고
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 클래스에 내 VanishingPoint 목록에 결과를 ListHelper 추가에 추가 CalculationHelper 메소드를 호출 목록에 교차점
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
저는 static을 사용했기 때문에 비 정적 메서드에 대한 객체 참조가 필요하지 않았습니다. 공개 ListHelper가 더 나은 해결책이 되겠습니까? – heyred