我已经使用 google.proto.Timestamp 成功编译了我的 .proto 文件,并使用 protoc 生成了 .cs 文件。我遇到的唯一问题是在我的 c# 代码中初始化。
我尝试了以下方法:
.proto 文件
message teststamp
{
string Name = 1 ;
string address = 2;
google.protobuf.Timestamp _timeStamp = 3;
}
Run Code Online (Sandbox Code Playgroud)
C#文件
teststamp test = new teststamp();
test.Name = "Test";
test.address = "Test_Test_TEST"
//Example 2 : POSIX
test._timeStamp.Seconds = DateTime.Now.Second;
test._timeStamp.Nanos = DateTime.Now.Second*1000 ;
Run Code Online (Sandbox Code Playgroud)
上面的编译没有错误,但给了我这个错误:Object reference not set to an instance of an object.我尝试了一些其他方法,但由于帮助较少,它无法修复错误。
请帮我解决这个问题
谢谢