What is the preferred naming convention for Func method parameters?

后端 未结 3 554
鱼传尺愫
鱼传尺愫 2021-02-07 00:45

I admit that this question is subjective but I am interested in the view of the community. I have a cache class that takes a cache loader function of type Func

3条回答
  •  生来不讨喜
    2021-02-07 00:59

    I typically actually use the work delegate in my naming, to make it obvious that this parameter is receiving a delegate. For example, I'd potentially name the above:

    public static class Cache
    {
        public TResult Get(string cacheKey, Func cacheLoadingDelegate) 
        {
            // Implementation
        }
    }
    

    I do this specifically to avoid confusion from the suggested naming in the question. cacheLoader sounds too much like an object, and loadResult like an object/type (the result itself). I also don't personally like using function or method, as a delegate is not actually a function, but rather a delegate - a type that references a function.

提交回复
热议问题