How can I write a generic anonymous method?

后端 未结 4 1830
半阙折子戏
半阙折子戏 2020-12-02 01:56

Specifically, I want to write this:

public Func, T> SelectElement = list => list.First();

But I get a syntax error

4条回答
  •  臣服心动
    2020-12-02 02:20

        public static void SomeContainerFunction()
        {
            const string NULL_VALUE = (string)null;
    
            Type GetValueType(T value) => value?.GetType() ?? typeof(T);
    
            var typeOfNullValue = GetValueType(NULL_VALUE);
    
            Debug.WriteLine($"Value: {NULL_VALUE}, Type: {typeOfNullValue}");
        }
    

提交回复
热议问题