static void Main(string[] args) { Console.WriteLine($"Result of 5.0 + 4.5 is: {getSum(5.0,4.5)}"); Console.WriteLine($"Result of 5.0 + 4.5 is: {getSum("5.0", "4.5")}"); carColor car1 = carColor.Blue; paintCar(car1); }
private static void Part4(string[] args) { double x = 5; double y = 4; Console.WriteLine("5+5 = {0}", GetSum(x, y)); Console.WriteLine(); //proves x didn't change in the function, and was passed by value int solution; DoubleIt(15, out solution); //works with values putside the method itself, and defines the value of a variable inside the method Console.WriteLine("15*2 = {0}", solution); int num1 = 10; int num2 = 20; Console.WriteLine("Before swap num1: {0} num2: {1}", num1, num2); Swap(ref num1, ref num2); Console.WriteLine("After swap num1: {0} num2: {1}", num1, num2); Console.WriteLine("1+2+3 = {0}", GetSumMore(1, 2, 3)); //named parameters PrintInfo(zipCode: 60053, name: "Tommy"); //overloads Console.WriteLine("5.0 + 4.5 = {0}", GetSum(5.0, 4.5)); Console.WriteLine("5+4 = {0}", GetSum(5, 4)); Console.WriteLine("5+4 = {0}", GetSum("5", "4")); //parameters have to be different to have an overloaded method //enums carColor cc = carColor.Blue; PaintCar(cc); }
private void btnAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(txtType.Text) && !string.IsNullOrWhiteSpace(txtMark.Text) && !string.IsNullOrWhiteSpace(txtModel.Text) && !string.IsNullOrWhiteSpace(txtPlate.Text) && !string.IsNullOrWhiteSpace(txtColor.Text) && !string.IsNullOrWhiteSpace(txtRate.Text) && !string.IsNullOrWhiteSpace(txtYear.Text) && numCap.Value != 0) { if (db.carTypes.FirstOrDefault(t => t.Name.ToLower() == txtType.Text.ToLower()) == null) { carType type = new carType(); type.Name = txtType.Text; db.carTypes.Add(type); db.SaveChanges(); } if (db.carMarks.FirstOrDefault(t => t.Name.ToLower() == txtMark.Text.ToLower()) == null) { carMark mark = new carMark(); mark.Name = txtMark.Text; db.carMarks.Add(mark); db.SaveChanges(); } if (db.carModels.FirstOrDefault(t => t.Name.ToLower() == txtModel.Text.ToLower()) == null) { carModel model = new carModel(); model.Name = txtModel.Text; model.MarkId = db.carMarks.FirstOrDefault(m => m.Name == txtMark.Text).Id; db.carModels.Add(model); db.SaveChanges(); } if (db.carColors.FirstOrDefault(t => t.Name.ToLower() == txtColor.Text.ToLower()) == null) { carColor color = new carColor(); color.Name = txtColor.Text; db.carColors.Add(color); db.SaveChanges(); } if (db.Cars.FirstOrDefault(p => p.Plate == txtPlate.Text) == null) { Car car = new Car(); car.MarkId = db.carMarks.FirstOrDefault(m => m.Name == txtMark.Text).Id; car.ModelId = db.carModels.FirstOrDefault(mo => mo.Name == txtModel.Text).Id; car.TypeId = db.carTypes.FirstOrDefault(t => t.Name == txtType.Text).Id; car.ColorId = db.carColors.FirstOrDefault(c => c.Name == txtColor.Text).Id; car.Year = Convert.ToInt32(txtYear.Text); car.SeatCapacity = Convert.ToInt32(numCap.Value); car.Rate = Convert.ToDecimal(txtRate.Text); car.Plate = txtPlate.Text; car.IsAviable = true; car.Note = rtbNote.Text; car.AddedDate = DateTime.Now; db.Cars.Add(car); db.SaveChanges(); MessageBox.Show("Car added sucessfully!"); fillDgv(db.Cars.ToList()); Reset(); } else { lblError.Text = "This plate already exists."; } } else { lblError.Text = "Please fill all required(*) data!"; } }
static void PaintCar(carColor carColor) { Console.WriteLine("The car was painted {0} with the code {1}", carColor, (int)carColor); }
static void paintCar(carColor cc) { Console.WriteLine($"The car was painted {cc} with code {(int)cc}"); }