Skip to content

Instantly share code, notes, and snippets.

@200even
Last active August 29, 2015 14:23
Show Gist options
  • Save 200even/486b509dfbe02d922207 to your computer and use it in GitHub Desktop.
Save 200even/486b509dfbe02d922207 to your computer and use it in GitHub Desktop.
// Assign "Hello World" to a variable message
var message = "Hello World";
// Assign a different string to a different variable
string different = message;
// Assign a number to a variable
var number = 23;
// Use string interpolation to display the number in a string
// i.e. string interpolation = "Hello {0}"
string leBron = String.Format("Hello {0}", number);
// Make an array of your favorite movies or books or bands. Have at least 4 values.
string[] movies = { "City Lights", "Unforgiven", "Jurassic Park", "Aliens" };
// Make a anonymous type object of information about yourself. Have at least 4 properties on the anoymous type
var scott = new
{
Name = "Scott Ferguson",
Age = 29,
Gender = Male,
IsAlive = true
};
// BONUS 1
// Make an array of anonymous types containing more information
// about your favorite movies. The type should have at least 3 keys+values
var movieInfo = new[]
{
new { Director = "Martin Scorcese", Movie = "The Departed", Actor = "Leonardo DiCaprio"},
new { Director = "Steven Spielberg", Movie = "Munich", Actor = "Eric Bana"},
new { Director = "John Ford", Movie = "The Searchers", Actor = "John Wayne"},
new { Director = "Roman Polanski", Movie = "Chinatown", Actor = "Jack Nickolson"}
};
// BONUS 2
// Use 'for loop' and loop through the array of anonymoous types and print only one of the properties
// For example { firstname = "Jimbob" } loop through and print only the firstname
for (int i = 0; i < movieInfo.Length; i++)
{
Console.WriteLine(movieInfo[i].Director);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment