C# Google Sheets APIv4 填充请求体

C# Google Sheets APIv4 filling requestbody

抱歉,如果这个问题很基础。 我正在尝试创建一个更新请求,以便用内容填充我的一些 googledocs 电子表格(顺便说一句,读取这些工作表的代码部分工作得很好),但是,充其量是中间的,我无法解决这个问题。

所以这是代码中有问题的部分:

 Data.ValueRange requestBody = new Data.ValueRange();
 var test = new string[] { "p1", "p2", "p3", "", "", "", "", "iwannadie" };
 requestBody.Values.Add(test);`

此代码的第三行returns System.NullReferenceException,对象引用未设置为对象的实例。 是什么赋予了?

requestBody.Values 的类型为 IList<IList<object>>,尝试改为使用此代码:
requestBody.Values.Add(new IList<object> { "", "", "" });

导致编译器错误 "Can not create instance of abstract class lol suffer"。 并尝试添加列表会产生编译器错误 "can not convert List into IList"。 请帮忙q-q

基本上,requestBody.Values 在您填充它之前将为空。

只需创建您自己的列表并用您的数组填充它,例如

var test = new string[] { "p1", "p2", "p3", "", "", "", "", "foo" };
requestBody.Values = new List<IList<object>> { test };