我在var sse12得到错误;像隐式本地类型变量必须初始化

时间:2018-06-11 07:34:59

标签: c# web-services

嗨我在var sse12收到错误;像隐式本地类型变量必须初始化请建议我实际上这里数据即将到来的Web服务

,代码是

private static void eCom4(DataServiceQuery<VEmployee4> vv, int sno)
    {
        System.Data.DataTable dt = new System.Data.DataTable();
        Console.WriteLine("processing 4...");
        string strEmp = string.Empty;
        string strFileNmae = "DSEmp_v4_20180607_Pipe";
        strEmp = "Source|Sno|FirstName|MiddleName|LastName |Email|EmployeeNo|CompanyCode|CompanyId|CompanyName|ADUsername|BusinessUnit|EmployeeNo|Title|FirstName|LastName|MiddleName|ADUsername|Email|DateOfBirth|Gender|PhoneNo|Nationality|MaritalStatus|Address|BusinessUnit|CostCenterCode|CompanyCode|CompanyId|CompanyName|DivisionId|DivisionName|DepartmentId|DepartmentName";
        writetxt(strFileNmae, strEmp);
        string strEmpCol = string.Empty;
        var compID = new int[] { 1, 2, 5, 8, 9, 10, 16, 19, 20, 21, 81, 90, 126, 391, 436, 451, 499, 501, 502, 503, 505 };
        //var compID = new int[] { 1, 2};
        for (int i = 0; i < compID.Length; i++)
        {
            int temp = compID[i];
            //string temp1 = Convert.ToString(compID[i]);                            
            var sse12;

            if (temp == 1)
            {

                sse12 = from sse1 in vv
                        where sse1.CompanyId == temp && sse1.DivisionId == 1021159
                        select sse1;
                //foreach (var item in sse12)
                //{
                //    strEmp = sno.ToString() + "|" + veCount.ToString() + "|" + item.FirstName + "|" + item.MiddleName + "|" + item.LastName + "|" + item.Email + "|" + item.EmployeeNo + "|" + item.CompanyCode + "|" + item.CompanyId + "|" + item.CompanyName + "|" + item.ADUsername + "|" + item.BusinessUnit + "|" + item.EmployeeNo + "|" + item.Title + "|" + item.FirstName + "|" + item.LastName + "|" + item.MiddleName + "|" + item.ADUsername + "|" + item.Email + "|" + item.DateOfBirth + "|" + item.Gender + "|" + item.PhoneNo + "|" + item.Nationality + "|" + item.MaritalStatus + "|" + item.Address + "|" + item.BusinessUnit + "|" + item.CostCenterCode + "|" + item.CompanyCode + "|" + item.CompanyId + "|" + item.CompanyName + "|" + item.DivisionId + "|" + item.DivisionName + "|" + item.DepartmentId + "|" + item.DepartmentName;
                //    Console.WriteLine("First Name ={0} && Comapny Id = {1}", item.FirstName, item.CompanyCode);
                //    writetxt(strFileNmae, strEmp);
                //}
            }
            else
            {

                sse12 = from sse1 in vv
                        where sse1.CompanyId == temp
                        select sse1;

} }

1 个答案:

答案 0 :(得分:3)

在C#中,var关键字用于让编译器在编译期间确定变量的类型(参见https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var)。

您无法在未初始化的情况下使用var关键字声明变量,并且必须指定其类型:

VEmployee4 sse12;