I have a series of names. I want to pick a random name, then capitalize the first character and use it as an initial, converted to a string.
For example, here is the list of names:
List<string> Name1 = new List<string>() {
"Aaron","Aron","Ron","Ronnie","Ronny","Abel","Abe","Abie","Abner","Abbie","Abraham","Abram","Abe","Abie","Bram","Adam","Addie","Addy","Ade","Adelbert","Adalbert","Ade","Bert","Bertie","Del","Adrian","Ade","Alan","Allan","Allen","Albert","Bert","Bertie","Alexander","Alex","Alec","Aleck","Lex","Sandy","Sander","Alfred","Alf","Alfie","Fred","Freddie","Freddy","Algernon","Algie","Algy","Alger","Alister","Allister","Alistair","Alastair","Alaster","Alonso","Alonzo","Lon","Lonnie","Lonny","Alphonso","Alfonso","Alf","Alfie","Alonso","Lon","Alva","Alvah","Alvan","Alvin","Alwin","Alwyn","Vin","Vinny","Win","Ambrose","Ambie","Brose","Amos","Andrew","Andy","Drew","Angus","Gus","Anselm","Ansel","Anse","Anthony","Antony","Anton","Tony","Archibald","Arch","Archie","Baldie","Arnold","Arnie","Arthur","Art","Artie","Augustus","August","Augie","Gus","Gussy","Gust","Gustus","Augustine","Augustin","Augie","Austin","Gus","Gussy","Gust","Austin","Avery","Avy","Baldwin","Baldie","Win","Barrett","Barry","Barrie","Bartholomew","Bart","Barty","Bartlett","Bartley","Bat","Batty","Basil","Baz","Basie","Benedict","Ben","Bennie","Benny","Benjamin","Ben","Bennie","Benny","Benjy","Benjie","Bennet","Bennett","Ben","Bennie","Benny","Bernard","Barnard","Bernie","Berney","Barney","Barnie","Bert","Bertie","Berthold","Bert","Bertie","Bertram","Bertrand","Bert","Bertie","Bill","Billy","Billie","Blair","Blake","Boris","Bradford","Brad","Ford","Bradley","Brad","Brady","Brandon","Branden","Brand","Brandy","Brenton","Brent","Bret","Brett","Brian","Bryan","Bryant","Broderick","Brodie","Brody","Brady","Rick","Ricky","Bruce","Bruno","Burton","Burt","Byron","Ron","Ronnie","Ronny","Caleb","Cal","Calvin","Cal","Vin","Vinny","Cameron","Cam","Ron","Ronny","Carey","Cary","Carry","Carl","Karl","Carol","Carrol","Carroll","Casey","Kasey","Caspar","Casper","Cas","Cass","Cassius","Cas","Cass","Cecil","Cis","Cedric","Ced","Rick","Ricky","Charles","Charlie","Charley","Chuck","Chad","Chas","Chester","Chet","Christian","Chris","Christy","Kit","Christopher","Kristopher","Chris","Kris","Cris","Christy","Kit","Kester","Kristof","Toph","Topher","Clarence","Clare","Clair","Clare","Clair","Clark","Clarke","Claude","Claud","Clayton","Clay","Clement","Clem","Clifford","Cliff","Ford","Clinton","Clint","Clive","Clyde","Cody","Colin","Collin","Cole","Conrad","Con","Connie","Conny","Corey","Cory","Cornelius","Connie","Conny","Corny","Corney","Cory","Craig","Curtis","Curt","Cyril","Cyrus","Dale","Daniel","Dan","Danny","Darrell","Darrel","Darryl","Daryl","Darry","David","Dave","Davey","Davie","Davy","Dean","Deane","Delbert","Del","Bert","Bertie","Dennis","Denis","Den","Denny","Derek","Derrick","Derry","Rick","Ricky","Desmond","Des","Dexter","Dex","Dominic","Dominick","Domenic","Domenick","Dom","Nick","Nicky","Don","Donnie","Donny","Donald","Don","Donnie","Donny","Donovan","Don","Donnie","Donny","Dorian","Douglas","Douglass","Doug","Doyle","Drew","Duane","Dwayne","Dudley","Dud","Duddy","Duke","Duncan","Dunny","Dunk","Dustin","Dusty","Dwight","Dylan","Dillon","Earl","Earle","Edgar","Eddie","Eddy","Ned","Edmund","Edmond","Eddie","Eddy","Ned","Ted","Edward","Eddie","Eddy","Ned","Ted","Teddy","Edwin","Eddie","Eddy","Ned","Egbert","Bert","Bertie","Elbert","Bert","Bertie","Eldred","Elijah","Elias","Eli","Lige","Elliot","Elliott","Ellis","Elmer","Elton","Alton","","Elvin","Elwin","Elwyn","Vin","Vinny","Win","Elvis","Elwood","Woody","Emery","Emmery","Emory","Emil","Emile","Emmanuel","Emanuel","Immanuel","Manuel","Manny","Mannie","Emmet","Emmett","Eric","Erik","Erick","Rick","Ricky","Ernest","Earnest","Ernie","Errol","Ervin","Erwin","Irvin","Irvine","Irving","Irwin","Erv","Vin","Win","Ethan","Eugene","Gene","Eustace","Stacy","Stacey","Evan","Everard","Everett","Fabian","Fabe","Fab","Felix","Lix","Ferdinand","Ferdie","Fred","Freddie","Fergus","Ferguson","Fergie","Floyd","Floy","Ford","Francis","Frank","Frankie","Franky","Fran","Franklin","Franklyn","Frank","Frankie","Franky","Frederick","Frederic","Fredrick","Fredric","Fred","Freddie","Freddy","Rick","Ricky","Fred","Freddie","Gabriel","Gabe","Gabby","Garrett","Garret","Gary","GarryGeoffrey","Jeffrey","Jeffery","Jeff","George","Georgie","Geordie","Gerald","Gerard","Gerry","Jerry","Gilbert","Gil","Bert","Glenn","Glen","Gordon","Gordy","Don","Graham","Grant","Gregory","Gregor","Greg","Gregg","Griffith","Griffin","Griff","Guy","Harold","Hal","Harry","Harris","Harrison","Harry","Harvey","Harve","Hector","Henry","Harry","Hank","Hal","Herbert","Herb","Bert","Bertie","Herman","Manny","Mannie","Hilary","Hillary","Hill","Hillie","Hilly","Homer","Horace","Horatio","Howard","Howie","Hubert","Hugh","Bert","Bertie","Hube","Hugh","Hughie","Hugo","Humphrey","Humphry","Humph","Ian","Ignatius","Iggy","Nate","Immanuel","Manny","Mannie","Irvin","Irvine","Irving","Irwin","Isaac","Isaak","Ike","Isidore","Isidor","Isadore","Isador","Izzy","Ivor","Jack","Jackie","Jacky","Jacob","Jake","Jay","James","Jim","Jimmy","Jimmie","Jamie","Jem","Jared","Jerry","Jarvis","Jervis","Jerry","Jason","Jay","Jasper","Jay","Jefferson","Jeff","Jeffrey","Jeffery","Geoffrey","Jeff","Jeremy","Jeremiah","Jerry","Jerome","Jerry","Jesse","Jess","Jessie","Jessy","Joel","Joe","John","Jack","Jackie","Jacky","Johnny","Jonathan","Jon","Jonny","Joseph","Joe","Joey","Jos","Jody","Joshua","Josh","Judson","Jud","Sonny","Julian","Julius","Jule","Jules","Justin","Jus","Just","Karl","Carl","Keith","Kelly","Kelley","Kelvin","Kel","Kelly","Kendall","Ken","Kenny","Kendrick","Ken","Kenny","Rick","Ricky","Kenneth","Ken","Kenny","Kent","Ken","Kenny","Kevin","Kev","Kirk","Kristopher","Kristofer","Kris","Kit","Kester","Kurt","Curt","Kyle","Lambert","Bert","Lamont","Monty","Monte","Lancelot","Launcelot","Lance","Laurence","Lawrence","Lorence","Lorenzo","Larry","Lars","Laurie","Lawrie","Loren","Lauren","Lee","Leigh","Leo","Leon","Lee","Leonard","Leo","Leon","Len","Lenny","Lennie","Leopold","Leo","Poldie","Leroy","Leeroy","Lee","Roy","Leslie","Lesley","Les","Lester","Les","Lewis","Lew","Lewie","Lincoln","Lin","Linc","Lynn","Lindon","Lyndon","Lin","Lynn","Lindsay","Lindsey","Lin","Lynn","Linus","Lionel","Leo","Leon","Llewellyn","Llew","Lyn","Lloyd","Loyd","Loyde","Floyd","Loy","Floy","Logan","Lonnie","Lonny","Louis","Lou","Louie","Lowell","Lovell","Lucian","Lucius","Luke","Luke","Lucas","Luke","Luther","Loot","Luth","Lyle","Lyall","Lynn","Malcolm","Mal","Malc","Mac","Manuel","Manny","Mannie","Marion","Mark","Marc","Marcus","Mark","Marc","Marshall","Marshal","Martin","Mart","Marty","Marvin","Mervin","Marv","Merv","Matthew","Matt","Mat","Matty","Mattie","Matthias","Matt","Mat","Matty","Mattie","Maurice","Morris","Morry","Morey","Moe","Maximilian","Max","Maxwell","Max","Maynard","Melvin","Mel","Merlin","Merle","Merrill","Merril","Merill","Michael","Mike","Mikey","Mick","Mickey","Micky","Miles","Myles","Milo","Milo","Milton","Milt","Mitchell","Mitch","Monroe","Munroe","Montague","Monty","Monte","Montgomery","Monty","Monte","Morgan","Mortimer","Mort","Morty","Morton","Mort","Morty","Moses","Moe","Mose","Moss","Murray","Murry","Nathan","Nathaniel","Nat","Nate","Natty","Neal","Neil","Nelson","Nel","Nell","Nels","Nevill","Nevil","Nevile","Neville","Nev","Newton","Newt","Nicholas","Nicolas","Nick","Nicky","Nicol","Cole","Colin","Nigel","Nige","Noah","Noel","Nowell","Norbert","Bert","Norris","Nor","Norrie","Norman","Norm","Normie","Nor","Norrie","Norton","Nort","Oliver","Ollie","Noll","Nollie","Nolly","Orson","Orville","Orv","Ollie","Osbert","Ossy","Ozzie","Ozzy","Bert","Osborn","Osborne","Ossy","Ozzie","Ozzy","Oscar","Ossy","Osmond","Osmund","Ossy","Ozzie","Ozzy","Oswald","Oswold","Ossy","Ozzie","Ozzy","Otis","Owen","Patrick","Pat","Paddy","Patsy","Paul","Pauly","Percival","Perceval","Percy","Perce","Perry","Peter","Pete","Petie","Petey","Philip","Phillip","Phil","Pip","Preston","Quentin","Quintin","Quenton","Quinton","Quinn","Quincy","Quincey","Quinn","Ralph","Raff","Rafe","Ralphy","Randall","Randal","Rand","Randy","Randolph","Rand","Randy","Dolph","Raphael","Rafael","Raff","Rafe","Raymond","Raymund","Ray","Reginald","Reg","Reggie","Renny","Rex","Rene","Reuben","Ruben","Rubin","Rube","Ruby","Reynold","Ray","Richard","Dick","Rick","Ricky","Rich","Richie","Rick","Ricky","Robert","Bob","Bobbie","Bobby","Dob","Rob","Robbie","Robby","Robin","Bert","Roderic","Roderick","Rod","Roddy","Rick","Ricky","Rodney","Rod","Roddy","Roger","Rodger","Rod","Roddy","Rodge","Roge","Roland","Rowland","Rolly","Roly","Rowly","Orlando","Rolph","Rolf","Rolfe","Roman","Rom","Romy","Ronald","Ron","Ronnie","Ronny","Ron","Ronnie","Ronny","Roscoe","Ross","Ross","Roy","Rudolph","Rudolf","Rudy","Rolf","Rolph","Dolph","Dolf","Rufus","Rufe","Rupert","Russell","Russel","Russ","Ryan","Samson","Sampson","Sam","Sammy","Samuel","Sam","Sammy","Sanford","Sandy","Ford","Saul","Scott","Scotty","Sean","Shaun","Shawn","Shane","Sebastian","Seb","Bass","Serge","Seth","Seymour","Morey","Shannon","Shanon","Sheldon","Shelly","Shel","Don","Shelley","Shelly","Shellie","Shel","Sherman","Shelton","Shelly","Shel","Tony","Sidney","Sydney","Sid","Syd","Silas","","Silvester","Sylvester","Syl","Vester","Simeon","Sim","Simie","Simmy","Simon","","Sim","Simie","Simmy","Solomon","Sol","Solly","Sal","Sonny","Son","Spencer","Stacy","Stacey","Stanley","Stan","Stephen","Steven","Stephan","Steffan","Stefan","Steve","Stevie","Steph","Steff","Stef","Stuart","Stewart","Stu","Stew","Terence","Terrence","Terrance","Terry","Thaddeus","Thadeus","Tad","Thad","Theodore","Theodor","Ted","Teddy","Theo","Terry","Thomas","Tom","Tommy","Timothy","Tim","Timmy","Tobias","Toby","Tobi","Tobie","Todd","Tony","Tracy","Tracey","Travis","Trav","Trenton","Trent","Trevor","Trev","Tristram","Tristam","Tristan","Tris","Troy","Tyler","Tyrone","Tyron","Ulysses","Uly","Uli","Lyss","Uriah","Urias","Uri","Uria","Valentine","Valentin","Val","Valerian","Valerius","Val","Van","Vance","Van","Vaughan","Vaughn","Vernon","Vern","Verne","Victor","Vic","Vick","Vincent","Vince","Vin","Vinny","Virgil","Vergil","Virge","Wallace","Wallis","Wally","Wallie","Waldo","Walter","Walt","Wally","Wallie","Warren","Wayne","Wesley","Wes","Wendell","Dell","Del","Wilbert","Will","Willie","Willy","Bert","Wilbur","Wilber","Will","Willie","Willy","Wiley","Will","Willie","Willy","Wilfred","Wilfrid","Will","Willie","Willy","Fred","Freddie","Freddy","Willard","Will","Willie","Willy","William","Bill","Billy","Billie","Will","Willie","Willy","Liam","Willis","Bill","Billy","Billie","Will","Willie","Willy","Wilson","Will","Willie","Willy","Winfred","Winfrid","Win","Winnie","Winny","Fred","Freddie","Freddy","Winston","Win","Winnie","Winny","Woodrow","Wood","Woody","Xavier","Zave","Zachary","Zachariah","Zacharias","Zack","Zacky","Zach"
};
I want to pick a random name (e.g. Will), then just take the first character (W), and convert that from a char
to a string
.
My random function is:
static System.Random rnd = new System.Random();
And my code, put together, reads:
string Initial = Name1[rnd.Next(Name1.Count)][0].ToString();
However, when I run the above code, I see the following error in Unity's console, pointing to the above line:
IndexOutOfRangeException: Index was outside the bounds of the array.
How can this be possible, if I'm only using an index provided within the total count of the list object?
I have also tried using Substring
:
string Initial = Name1[rnd.Next(Name1.Count)].Substring(0,1);
This throws the following error:
ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
This is just as confusing, as it implies (from what I can understand) that the string I've found is less than one character long. How can this be possible?
Aucun commentaire:
Enregistrer un commentaire