我有一个DateTime?变量,有时值是null,我怎么能在值为时返回空字符串"",null或者DateTime在没有时返回值null?
我在类中有以下字段定义:
public Nullable<System.Guid> GlobalId { get; set; }
Run Code Online (Sandbox Code Playgroud)
我有另一个课程如下:
public string GlobalId { get; set; }
Run Code Online (Sandbox Code Playgroud)
我想将类型为System.Guid的字段的值放入字符串中.
我试着这样做:
var questionIds = _questionsRepository.GetAll()
.Where(m => m.Problem != null &&
m.Problem.SubTopic != null &&
m.Problem.SubTopic.Topic != null &&
m.Problem.SubTopic.Topic.SubjectId == 1)
.Select(m => new QuestionHeader { GlobalId = (string) m.GlobalId })
.ToList();
return questionIds;
Run Code Online (Sandbox Code Playgroud)
但它给了我一个错误说:
Cannot convert type 'System.Guid?' to 'string'
Run Code Online (Sandbox Code Playgroud)
谁能告诉我怎么做到这一点?