我有一些数据存储在名为result
的变量中以下是数据的外观:
public void setMultiAnswer()
{
try
{
string question = "Question 1"
responsesList.Add("Answer1");
responsesList.Add("Answer2");
questionResponsesList.Add(false);
questionResponsesList.Add(true);
using (Entities testEntity = new Entities())
{
Question questionObj = new Question();
questionObj.Question1 = question;
questionObj.CreatedBy = "test";
questionObj.CreatedDate = DateTime.Now;
QuestionRespons questionResponsesObj = new QuestionRespons();
// fill response
foreach (var questionResponse in questionResponsesList)
{
questionResponsesObj.CorrectResponse = questionResponse;
}
questionObj.QuestionResponses.Add(questionResponsesObj);
Response responseObj = new Response();
// fill response
foreach (var response in responsesList)
{
responseObj.Response1 = response;
responseObj.CreatedBy = "test";
responseObj.CreatedDate = DateTime.Now;
}
questionResponsesObj.Response = responseObj;
testEntity.Questions.Add(questionObj);
testEntity.SaveChanges();
}
}
catch (Exception ex)
{
Console.Write(ex);
}
我要做的是计算结果的数量,在这种情况下为2
所以我做到了这一点:
警报(result.length);
但这回归“未定义”..我该怎么做?
答案 0 :(得分:-1)
尝试此代码可能会以计算对象
的方式工作 var foo = {"key1": "value1", "key2": "value2", "key3": "value3"};
var count = 0;
for (var k in foo) {
if (foo.hasOwnProperty(k)) {
++count;
}
}
alert("Found " + count + " properties specific to foo");