C # practice capture

Source: Internet
Author: User
Using system; namespace z1_jiuns {public class z1_jiu {public static void main () {string [] namelist = NULL; createnamelist (ref namelist); string [] afternamelist; zhua (namelist, out afternamelist); printnamelist (afternamelist); console. readkey ();} public static void createnamelist (ref string [] beforelist) {beforelist = new string [5]; beforelist [0] = "James "; beforelist [1] = ""; beforelist [2] = ""; beforelist [3] = "Zhao "; beforelist [4] = "Sun Qi ";} public static void zhua (string [] beforelist, out string [] afterlist) {afterlist = new string [1]; int tmpindex =-1; system. random ran = new random (); If (beforelist. length> 0) {console. writeline ("starting to capture failed:"); int tmplength = beforelist. length; For (INT I = 0; I <tmplength; I ++) {console. writeline ("Please press enter to capture details"); console. readline (); tmpindex = ran. next (0, beforelist. length); console. writeline ("the person caught this time" + beforelist [tmpindex]); insertafterlist (beforelist [tmpindex], ref afterlist); removefrombeforelist (tmpindex, ref beforelist);} console. writeline ("Capture ended") ;}} public static void insertafterlist (string insertname, ref string [] afterlist) {afterlist [afterlist. length-1] = insertname; string [] longlist = new string [(afterlist. length + 1)]; for (INT I = 0; I <afterlist. length; I ++) {longlist [I] = afterlist [I];} afterlist = longlist; longlist = NULL;} public static void removefrombeforelist (INT removeindex, ref string [] beforelist) {If (removeindex = (beforelist. length-1) {beforelist [removeindex] = "";} else {int I = 0; for (I = removeindex; I <(beforelist. length-1); I ++) {beforelist [I] = beforelist [I + 1] ;}} if (beforelist. length> 1) {string [] shortlist = new string [(beforelist. length-1)]; for (INT I = 0; I <beforelist. length-1; I ++) {shortlist [I] = beforelist [I];} beforelist = shortlist; shortlist = NULL;} else {beforelist = NULL ;}} public static void printnamelist (string [] list) {console. writeline ("output personnel list below:"); For (INT I = 0; I <list. length; I ++) {console. write (list [I] + "\ t");} console. writeline (); console. writeline ("End of output personnel List ");}}}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.