ควรใช้ฟังก์ชั่นที่ทำหน้าที่เป็นพารามิเตอร์หรือไม่และนำพารามิเตอร์ไปใช้กับฟังก์ชันเหล่านั้นเป็นพารามิเตอร์ด้วยหรือไม่
ฉันมักจะพบว่าตัวเองกำลังเขียนฟังก์ชั่นที่มีลักษณะเช่นนี้เพราะพวกเขาทำให้ฉันสามารถเข้าถึงข้อมูลได้อย่างง่ายดายและยังมีลายเซ็นที่ยอมรับพารามิเตอร์เพื่อกำหนดข้อมูลที่จะเข้าถึง public static string GetFormattedRate( Func<string, RateType>> getRate, string rateKey) { var rate = getRate(rateKey); var formattedRate = rate.DollarsPerMonth.ToString("C0"); return formattedRate; } หรือ public static string GetFormattedRate( Func<RateType, string> formatRate, Func<string, RateType>> getRate, string rateKey) { var rate = getRate(rateKey); var formattedRate = formatRate(rate); return formattedRate; } จากนั้นฉันก็ใช้สิ่งนี้: using FormatterModule; …