c# winforms how to repeat string array members? -


first, need create string array datagridview.selectedcells.values. need append string itself, until limit of member.count reached. example, if

string [] = {"a", "b", "c"};  // abc selectedcells.values. 

the new string [] should be:

{"a", "b", "c", "a", "b", "c", "a", "b"}

  • if limit 8, example.

how solve this, please?

you can use % (modulus) in loop.

string[] oldarr = new string[3] {"a","b","c"}; string[] newarr = new string[8]; int limit = 8; ( int = 0 ; < limit ; i++ ) {     newarr[i] = oldarr[i%oldarr.length]; } 

that's it.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -