Created
November 7, 2015 00:46
-
-
Save mfifth/30188117def84bf11b05 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsoleApplication4 | |
{ | |
class Program | |
{ | |
//Main Program | |
static void Main(string[] args) | |
{ | |
//New instance of car with parameters. Call function printcardetails on said instance. Which prints the string to the console. | |
Car mycar = new Car("BMW", "745li", 2005, "Black"); | |
printCarDetails(mycar); | |
Console.ReadLine(); | |
} | |
//New method which writes a string to the console and is attached to another method below (FormatMe). | |
private static void printCarDetails(Car car) | |
{ | |
Console.WriteLine("Here are the car details: {0}", | |
car.FormatMe()); | |
} | |
} | |
//New blueprint of class being created | |
class Car | |
{ | |
//Parameters of said class | |
public string Make { get; set; } | |
public string Model { get; set; } | |
public int Year { get; set; } | |
public string Color { get; set; } | |
//public method that calls all parameters within a single string of code | |
public string FormatMe() | |
{ | |
return String.Format("{0} - {1} - {2} - {3}", | |
this.Make, | |
this.Model, | |
this.Color, | |
this.Year); | |
} | |
//Constructor for Car to take parameters when new Car is created | |
public Car(string make, string model, int year, string color) | |
{ | |
Make = make; | |
Model = model; | |
Year = year; | |
Color = color; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment