c# - Join an array of strings into a single string -


my question system.random command in c#.

i have query in mvc 4 project like:

public jsonresult getquestions()  {     ...     var rnd = new random();     var selecteddata = data.select(y => new      {          ...,         qanswers = ((y.qa1 != null ? "ab" : "") +                     (y.qa2 != null ? "cd" : "") +                    (y.qa3 != null ? "ef" : "") +                    (y.qa4 != null ? "gh" : "") +                    (y.qa5 != null ? "ij" : "")).orderby(item => rnd.next())     });      return json(selecteddata, jsonrequestbehavior.allowget);  } 

as result of query, want see like:

ijcdefabgh

but result is:

["i","a","c","d","g","h","e","f","b","j"] 

do know mistake? or how can fix it?

you must create string array in order have "pairs" string, , shuffle it,something like:

var qanswers = string.concat(new string[] { (y.qa1 != null ? "ab" : "" ),                (y.qa2 != null ? "cd" : ""),                (y.qa3 != null ? "ef" : ""),                (y.qa4 != null ? "gh" : ""),                (y.qa5 != null ? "ij" : "")}                  .where(item=>!string.isnullorempty(item))                  .orderby(item=>rnd.next()));  

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -