I have seen a video tutorial in C# and I followed it to learn C#. However, I am not sure if the author does follow best practice or not. What I asked myself about is why didn't he create a method to print the speed rather than Console.WritLine that in two different methods As follow:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace understandingOO
{
class Auto
{
public string Make;
public string Model;
public int Year;
public string color;
public int Miles;
public int Speed;
public void Accelerate()
{
Speed++;
Console.WriteLine("Current Speed: " + Speed);
}
public void Deaccelerate()
{
Speed--;
Console.WriteLine("Current Speed: " + Speed);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace understandingOO
{
class Program
{
static void Main(string[] args)
{
Auto myCar = new Auto();
myCar.Make = "Toyota";
myCar.Miles = 5000;
myCar.Model = "Cutlas..";
myCar.Speed = 0;
myCar.Year = 2011;
myCar.Accelerate();
myCar.Accelerate();
myCar.Accelerate();
myCar.Deaccelerate();
Console.ReadLine();
}
}
}