다른 메서드로 조건을 동작으로 전달하려고합니다. "ComputerPriceGenerator"의 첫 번째 줄은 작동하지만, 어떻게 배열 작업 (두 번째 줄)를 만들기 위해? ..C# 동작 <T>, 매개 변수로 함수 전달
내가 조언을 찾고 있어요 어떤 아이디어가 ..., CalculateAllPrice이
public void ComputerPriceGenerator()
{
//Below line Works
PriceMachine.CalculatePrice(cart.Computers[0],() => ComputerConverter(cart.Computers[0]));
//How to make this work, i don't want to loop it???
PriceMachine.CalculateAllPrice(cart.Computers,() => ComputerConverter(??));
}
public void ComputerConverter(Computer comp)
{
if (comp.Memory <= 2)
comp.Discount = 10;
}
귀하의 코드는 LINQ를 사용할 수있는 좋은 후보했을 것이다, 그러나 그것은 부작용이 가득합니다. 나는 리팩토링을 고려할 것이다. –
CalculatePrice 및 CalculateAllPrice의 서명을 보여주지 않으면 어떻게 도와 줄지 알 수 없습니다. –
@Jon Skeet : CalculateAllPrice의 서명이 무엇인지에 관해서 부분적으로 조언을 구하는 것처럼 보였습니다. 그래도 나는 잘못 될 수 있습니다. –