编译时出现多个意外错误
本文关键字:意外 错误 编译 | 更新日期: 2023-09-27 18:24:18
我的代码中出现了这些奇怪的编译器错误:
} expected
Invalid token 'return' in class, struct, or interface member declaration
Method must have a return type
Identifier expected
; expected
Type or namespace definition, or end-of-file expected
所有这些误差都集中在GetTicketInfo
方法上。
这段代码几天来一直在编译和工作,现在Visual Studio 2012突然出现了问题
我做错了什么?代码如下。
using System;
using System.Linq;
namespace www.classes
{
public class HelpDeskTicket
{
public int TicketId { get; set; }
public String Title { get; set; }
public String Description { get; set; }
public String Category { get; set; }
public String Requestor { get; set; }
public String Status { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime DueDate { get; set; }
public long CategoryId { get; set; }
public long StatusId { get; set; }
public String TicketType { get; set; }
public Guid RequestedBy { get; set; }
public Guid AssignedTo { get; set; }
public String AssignedToName { get; set; }
public String ImpactAnalysis { get; set; }
public String TestingRequirements { get; set; }
public String ImpactOnSOP { get; set; }
public String TrainingRequirements { get; set; }
public String SourceVersion { get; set; }
public int ReleaseNumber { get; set; }
public DateTime UATApprovalDate { get; set; }
public String UATUserName { get; set; }
public Guid? UATUserID { get; set; }
public DateTime SecurityApprovalDate { get; set; }
public Guid? SecurityOfficer { get; set; }
public String SecurityUserName { get; set; }
public DateTime PrivacyApprovalDate { get; set; }
public Guid? PrivacyOffcer { get; set; }
public String PrivacyUserName { get; set; }
public DateTime CIOApprovalDate { get; set; }
public DateTime? ITApprovalDate { get; set; }
public String ITApproverName { get; set; }
public Guid? ITApprovalBy { get; set; }
public Guid? CIO { get; set; }
public String CIOUserName { get; set; }
public DateTime ProductionDate { get; set; }
private static IQueryable<HelpDeskTicket> GetInfo(int ticketId, DbDataContext dc, DateTime _default)
{
return from ticket in dc.TicketLists
join category in dc.TicketCategories on ticket.CategoryID equals category.TicketCategoryID
join status in dc.StatusLists on ticket.StatusID equals status.StatusID
where ticket.TicketID == ticketId
select new HelpDeskTicket
{
TicketId = ticket.TicketID,
Title = ticket.Title,
Description = ticket.Description,
Category = category.CategoryName,
Requestor = GetRequestor(ticket.RequestedBy.Value, dc),
Status = status.Status,
CreatedOn = ticket.CreatedOn,
DueDate = ticket.DueDate.HasValue ? ticket.DueDate.Value : _default,
CategoryId = ticket.CategoryID.Value,
StatusId = ticket.StatusID.Value,
TicketType = ticket.TicketType,
RequestedBy = ticket.RequestedBy.Value,
AssignedTo = ticket.AssignedTo.Value,
AssignedToName = GetAssignee(ticket.AssignedTo.Value, dc),
ImpactAnalysis = ticket.ImpactAnalysis,
TestingRequirements = ticket.TestingReq,
ImpactOnSOP = ticket.ImpactOnSOP,
TrainingRequirements = ticket.TrainingReq,
SourceVersion = ticket.SourceVersion,
ReleaseNumber = ticket.ReleaseNumber.GetValueOrDefault(0),
UATUserID = ticket.UATUserid,
UATApprovalDate =
ticket.UATApprovalDate.HasValue ? ticket.UATApprovalDate.Value : _default,
UATUserName = GetTester(ticket.UATUserid.Value, dc),
SecurityOfficer = ticket.SecurityUserid,
SecurityUserName = GetSecurityOfficer(ticket.SecurityUserid.Value, dc),
SecurityApprovalDate =
ticket.SecurityApprovalDate.HasValue
? ticket.SecurityApprovalDate.Value
: _default,
PrivacyOffcer = ticket.PrivacyUserid,
PrivacyUserName = GetPrivacyOfficer(ticket.PrivacyUserid.Value, dc),
PrivacyApprovalDate =
ticket.PrivacyApprovalDate.HasValue
? ticket.PrivacyApprovalDate.Value
: _default,
CIO = ticket.CIOUserid,
CIOUserName = GetCIO(ticket.CIOUserid, dc),
CIOApprovalDate =
ticket.CIOApprovalDate.HasValue ? ticket.CIOApprovalDate.Value : _default,
ProductionDate =
ticket.ProductionDate.HasValue ? ticket.ProductionDate.Value : _default,
ITApproverName = GetITApprovalUser(ticket.ITUserId, dc),
ITApprovalDate = ticket.ITApprovalDate,
ITApprovalBy = ticket.ITUserId
};
}
public static HelpDeskTicket GetTicketInfo(int ticketId, DbDataContext dc)
{
private DateTime _default = new DateTime(1900, 1, 1);
return GetInfo(ticketId, dc, _default).SingleOrDefault();
}
}
}
public static HelpDeskTicket GetTicketInfo(int ticketId, DbDataContext dc)
{
private DateTime _default = new DateTime(1900, 1, 1);
return GetInfo(ticketId, dc, _default).SingleOrDefault();
}
我确信这段代码几天前不起作用,像你那样使用访问修饰符private
是不合法的,只需将其删除即可。
虽然这不是StackOverflow喜欢的问题类型,但我们都曾犯过愚蠢的错误。这是一个语法问题。
从方法内部删除private
关键字。
private DateTime _default = new DateTime(1900, 1, 1);
至
DateTime _default = new DateTime(1900, 1, 1);