컴파일러 오류 CS0845

업데이트: 2007년 11월

오류 메시지

람다 식 트리에는 왼쪽에 null 리터럴이 있는 병합 연산자를 포함할 수 없습니다.
An expression tree lambda may not contain a coalescing operator with a null literal left-hand side.

null 자체는 형식이 없기 때문에 null에 대해서는 병합 연산자가 작동하지 않습니다.

이 오류를 해결하려면

  • 개체에 null 리터럴을 캐스팅합니다.

예제

다음 코드에서는 CS0845 오류가 발생하는 경우를 보여 줍니다.

// cs0845.cs
using System;
using System.Linq;
using System.Linq.Expressions;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Expression<Func<object>> e = () => null ?? null; // CS0845
            // Try the following line instead.
            // Expression<Func<object>> e = () => (object)null ?? null;
        }
    }
}