[ # ] Random Value Generator with String Arrays in C#

/* Posted March 10th, 2008 at 1:00pm */
/* Filed under C# */

 The code below selects a random variable from an array of strings, demonstrating the random feature in c#

Code below…



_________________________________________________________________
protected void Page_Load(object sender, EventArgs e)

{
// Initialize the string array


string[] strStrings = { “Timmy”, “Edgar”, “Jason”, “Mike”, “Buck”, “Kelly” };

// Choose a random slogan

string person = randomPerson(strStrings);

Response.Write(person);
// Display the random slogan


}

public static string randomPerson (string[] people)

{
Random RandString = new Random();

string person = people[RandString.Next(0, people.Length)];

return person;

}
________________________________________________________________

  • Digg
  • del.icio.us
  • Propeller
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Mixx
  • NewsVine
  • Blogsvine
  • Facebook
  • Google
  • TwitThis


Related Posts

Leave a Reply


*


* (not published, used to display your gravatar)



(* required)

Anything Geeky Goes!

Highlights

Featured Wii

Featured iPhone

Featured PSP/PS3

Featured A/V

Related Links

Archives

Products Highlight


Featured Sites

Categories

Subscribe

Recent Posts

Commentors

Other Links