How to do it on one line?

I am a little versed in this, but I'm a little new to C #

ResponseList responsesList = new ResponseList();
PagedResponseList pagedResponsesList = new PagedResponseList();
responsesList = responseService.ListSurveyResponses(1000);
pagedResponsesList = responsesList.ResultData;

This is probably easy, but the syntax needed for a one-liner eludes me.

+3
source share
4 answers
var pagedResponsesList = responseService.ListSurveyResponses(1000).ResultData;
+5
source

Firstly, you really do not need two statements newin your first two lines, since those instances newwill be overwritten by what you assigned in the last two lines.

If you are new to C #, I suggest sticking to two lines at least so that you understand at least what happens in the steps. In particular, the last two lines:

ResponseList responsesList = responseService.ListSurveyResponses(1000);
PagedResponseList pagedResponsesList = responsesList.ResultData;

, responsesList , , ( , .ResultData responseService.ListSurveyResponses()):

PagedResponseList pagedResponsesList = responseService.ListSurveyResponses(1000).ResultData;
+7

Like others, you can put it all on one line like this:

var pagedResponsesList = responseService.ListSurveyResponses(1000).ResultData;

But I think that, given that you are calling another service, you really want to do some exception handling, check your result to null before referring to .ResultDataetc.

+1
source
PagedResponseList pagedResponsesList=responseService.ListSurveyResponses(1000).ResultData
0
source

All Articles