// Assign "Hello World" to a variable message
String Message = "Hello, my friends";
Console.WriteLine(Message);
Console.Read();
// Assign a different string to a different variable
String Variable = "this is the first version";
Console.WriteLine(Variable);
Variable = "this is the second version";
Console.WriteLine(Variable);
Console.Read();
// Assign a number to a variable
int number;
number = 4;
Console.WriteLine(number);
Console.Read();
// Use string interpolation to display the number in a string
// i.e. string interpolation = "Hello {0}"
Console.WriteLine("Hello {0}", "bob", "tom");
Console.Read();
// Make an array of your favorite movies or books or bands. Have at least 4 values.
String[] MikesBooks = new String[] {
"Zen and the Art of Motorcycle Maintenance",
"Dune",
"The Fountainhead",
"Brave New World",
"Fahrenheit 451"
};
int i;
for (i = 0; i < 5; i++)
{
Console.WriteLine(MikesBooks[i]);
}
Console.Read();
// Make a anonymous type object of information about yourself. Have at least 4 properties on the anoymous type
var MikeNull = new { age = 48, MiddleInitial = "K", Married = true, Alive = true };
Console.WriteLine("Michael Null's personal info");
Console.WriteLine("age: " + MikeNull.age);
Console.WriteLine("Middle Initial: "+ MikeNull.MiddleInitial);
Console.WriteLine("Married: " + MikeNull.Married);
Console.WriteLine("Alive: " + MikeNull.Alive);
Console.Read();
// 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 Star_Wars = new
{
Title = "Star Wars", Subtitle = "Episode IV, A New Hope", Release_Year = 1977, Box_Office = 10.7, D3 = false };
var Blade_Runner = new { Title = "Blade Runner", Subtitle = "The Director's Cut", Release_Year = 1982, Box_Office = 9.8, D3 = true };
var Avatar = new { Title = "Avatar", Subtitle = "That movie about the blue chick", Release_Year = 2011, Box_Office = 4.5, D3 = true };
Console.WriteLine("Title: " + Star_Wars.Title);
Console.WriteLine("Subtitle: " + Star_Wars.Subtitle);
Console.WriteLine("Available in 3D: " + Star_Wars.D3);
Console.WriteLine(string.Empty);
Console.WriteLine("Title: " + Blade_Runner.Title);
Console.WriteLine("Box Office Gross in Millions: " + Blade_Runner.Box_Office);
Console.WriteLine(string.Empty);
Console.WriteLine("Title: " + Avatar.Title);
Console.WriteLine("Also Known as: " + Avatar.Subtitle);
Console.Read();
// 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
var movieInfo = new[]
{
new { Title ="Bob's Excellent movie", Genre = "Stupid", d3 = false, BoxOffice = 2.1},
new { Title ="Tom's Horrible documentary", Genre = "Crazy", d3 = true, BoxOffice = 8.5},
new { Title ="Fred's New Chair", Genre = "Thoughtful", d3 = false, BoxOffice = 1.5}
};
int j;
for (j = 0; j < 3; j++)
{
Console.Write("The Title is: " + movieInfo[j].Title);
Console.WriteLine(" and the Genre is " + movieInfo[j].Genre);
Console.WriteLine(string.Empty);
}
Console.Read();
I like that you saw that Console.WriteLine() can work similiarly to string.Format(). In that you can pass the format and arguments to Console.WriteLine()
// Assign "Hello World" to a variable message String Message = "Hello, my friends"; Console.WriteLine(Message); Console.Read(); // Assign a different string to a different variable String Variable = "this is the first version"; Console.WriteLine(Variable); Variable = "this is the second version"; Console.WriteLine(Variable); Console.Read();
// Assign a number to a variable int number; number = 4; Console.WriteLine(number); Console.Read();
// Use string interpolation to display the number in a string // i.e. string interpolation = "Hello {0}" Console.WriteLine("Hello {0}", "bob", "tom");
// Make an array of your favorite movies or books or bands. Have at least 4 values. String[] MikesBooks = new String[] { "Zen and the Art of Motorcycle Maintenance", "Dune", "The Fountainhead", "Brave New World", "Fahrenheit 451" }; int i; for (i = 0; i < 5; i++) { Console.WriteLine(MikesBooks[i]); } Console.Read();
// Make a anonymous type object of information about yourself. Have at least 4 properties on the anoymous type var MikeNull = new { age = 48, MiddleInitial = "K", Married = true, Alive = true }; Console.WriteLine("Michael Null's personal info"); Console.WriteLine("age: " + MikeNull.age); Console.WriteLine("Middle Initial: "+ MikeNull.MiddleInitial); Console.WriteLine("Married: " + MikeNull.Married); Console.WriteLine("Alive: " + MikeNull.Alive);
// 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 Star_Wars = new { Title = "Star Wars", Subtitle = "Episode IV, A New Hope", Release_Year = 1977, Box_Office = 10.7, D3 = false }; var Blade_Runner = new { Title = "Blade Runner", Subtitle = "The Director's Cut", Release_Year = 1982, Box_Office = 9.8, D3 = true }; var Avatar = new { Title = "Avatar", Subtitle = "That movie about the blue chick", Release_Year = 2011, Box_Office = 4.5, D3 = true }; Console.WriteLine("Title: " + Star_Wars.Title); Console.WriteLine("Subtitle: " + Star_Wars.Subtitle); Console.WriteLine("Available in 3D: " + Star_Wars.D3); Console.WriteLine(string.Empty); Console.WriteLine("Title: " + Blade_Runner.Title); Console.WriteLine("Box Office Gross in Millions: " + Blade_Runner.Box_Office); Console.WriteLine(string.Empty); Console.WriteLine("Title: " + Avatar.Title); Console.WriteLine("Also Known as: " + Avatar.Subtitle); Console.Read();
// 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 var movieInfo = new[] { new { Title ="Bob's Excellent movie", Genre = "Stupid", d3 = false, BoxOffice = 2.1}, new { Title ="Tom's Horrible documentary", Genre = "Crazy", d3 = true, BoxOffice = 8.5}, new { Title ="Fred's New Chair", Genre = "Thoughtful", d3 = false, BoxOffice = 1.5} }; int j; for (j = 0; j < 3; j++) { Console.Write("The Title is: " + movieInfo[j].Title); Console.WriteLine(" and the Genre is " + movieInfo[j].Genre); Console.WriteLine(string.Empty); } Console.Read();
https://gist.github.com/michaelnull/1646776c1d24a5cbe72e#file-day-1-cs