Yarden
Yarden
Explore posts from servers
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
Was very helpful
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
Thank you so so so so so much ❤️
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
Ohhh okie!
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
But what is the difference? When I didn't use override the same output was printed. You named it "overshadowing", but what exactly the difference? it seems like a similar effect
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
Isn't overriding means to use the same name but change the logic in the son's class? That's exactly what was told in Java
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewClass
{
sealed class Car : Vehicle
{
private static int carsCreated;
private int id;
Radio radio = new Radio();//Has-a
public Car(string brand, string model, string color, int year, int numberOfWheels)
: base(brand, model, color, year, numberOfWheels)
{
id = carsCreated++;
}
public int getID()
{
return id;
}
public string getRadioColor()
{
return "string";
}
static Car()
{
carsCreated = 0;
}
public static void Main(string[] args)
{
//Car car0 = Car("Mitsubishi", "Space star", "Blue", 2018);
Car car1 = new Car("Mitsubishi", "Space star", "Blue", 2018, 5);
Car car2 = new Car("BMW", "X5 SUV", "White", 2022, 4);
Car car3 = new Car("Alfa Romeo", "Giulietta", "Red", 2024, 4);
Car car4 = new Car("Suzuki", "Baleno", "White", 1996, 4);

car1.setRadioColor("Red");

Car[] cars = new Car[] { car1, car2, car3, car4 };

//Iteration over the items of cars:
foreach (Car item in cars)
{
Console.WriteLine("Brand: {0}, Model: {1}, Color: {2}, Year: {3}, ID: {4}", item.getBrand(), item.getModel(), item.Color, item.Year, item.getID());
Console.WriteLine("car radio's color: {0}", item.getRadioColor());
}

Console.WriteLine(car1.getRadioColor());
Console.ReadLine();
}
}
}
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewClass
{
sealed class Car : Vehicle
{
private static int carsCreated;
private int id;
Radio radio = new Radio();//Has-a
public Car(string brand, string model, string color, int year, int numberOfWheels)
: base(brand, model, color, year, numberOfWheels)
{
id = carsCreated++;
}
public int getID()
{
return id;
}
public string getRadioColor()
{
return "string";
}
static Car()
{
carsCreated = 0;
}
public static void Main(string[] args)
{
//Car car0 = Car("Mitsubishi", "Space star", "Blue", 2018);
Car car1 = new Car("Mitsubishi", "Space star", "Blue", 2018, 5);
Car car2 = new Car("BMW", "X5 SUV", "White", 2022, 4);
Car car3 = new Car("Alfa Romeo", "Giulietta", "Red", 2024, 4);
Car car4 = new Car("Suzuki", "Baleno", "White", 1996, 4);

car1.setRadioColor("Red");

Car[] cars = new Car[] { car1, car2, car3, car4 };

//Iteration over the items of cars:
foreach (Car item in cars)
{
Console.WriteLine("Brand: {0}, Model: {1}, Color: {2}, Year: {3}, ID: {4}", item.getBrand(), item.getModel(), item.Color, item.Year, item.getID());
Console.WriteLine("car radio's color: {0}", item.getRadioColor());
}

Console.WriteLine(car1.getRadioColor());
Console.ReadLine();
}
}
}
This is the son's class, I override this method and used it
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
namespace NewClass
{
public class Vehicle
{
private string brand;
private string model;
private string color;
private int year;
private int numOfWheels;
private Radio radio = new Radio();//Has-a

protected Vehicle(string brand, string model, string color, int year, int numberOfWheels)
{
this.brand = brand;
this.model = model;
this.color = color;
this.year = year;
this.numOfWheels = numberOfWheels;
}
public int NumberOfWheels
{
get { return numOfWheels; }
set { numOfWheels = value; }
}
protected string getBrand()
{
return brand;
}
protected void setBrand(string brand) => this.brand = brand;
protected string getModel()
{
return model;
}
protected void setModel(string model) => this.model = model;
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public int Year
{
get { return year; }
set
{
this.year = value;
}
//get => year;
//set => year = value;
}

public void setRadioColor(string color)
{
radio.setColor(color);
}
public string getRadioColor()
{
return radio.getColor();
}
//public static void Main(string[] args)
//{
// Vehicle vehicle = new Vehicle("1", "2", "3", 1, 2);
// vehicle.numOfWheels = 10;
// Console.WriteLine(vehicle.numOfWheels);

// Console.ReadLine();
//}

}


}
namespace NewClass
{
public class Vehicle
{
private string brand;
private string model;
private string color;
private int year;
private int numOfWheels;
private Radio radio = new Radio();//Has-a

protected Vehicle(string brand, string model, string color, int year, int numberOfWheels)
{
this.brand = brand;
this.model = model;
this.color = color;
this.year = year;
this.numOfWheels = numberOfWheels;
}
public int NumberOfWheels
{
get { return numOfWheels; }
set { numOfWheels = value; }
}
protected string getBrand()
{
return brand;
}
protected void setBrand(string brand) => this.brand = brand;
protected string getModel()
{
return model;
}
protected void setModel(string model) => this.model = model;
public string Color
{
get { return this.color; }
set { this.color = value; }
}
public int Year
{
get { return year; }
set
{
this.year = value;
}
//get => year;
//set => year = value;
}

public void setRadioColor(string color)
{
radio.setColor(color);
}
public string getRadioColor()
{
return radio.getColor();
}
//public static void Main(string[] args)
//{
// Vehicle vehicle = new Vehicle("1", "2", "3", 1, 2);
// vehicle.numOfWheels = 10;
// Console.WriteLine(vehicle.numOfWheels);

// Console.ReadLine();
//}

}


}
This is the base class, look at the method "getRadioColor"
23 replies
CC#
Created by Yarden on 11/20/2024 in #help
✅ override and virtual
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace NewClass { public class Vehicle { private string brand; private string model; private string color; private int year; private int numOfWheels; private Radio radio = new Radio();//Has-a protected Vehicle(string brand, string model, string color, int year, int numberOfWheels) { this.brand = brand; this.model = model; this.color = color; this.year = year; this.numOfWheels = numberOfWheels; } public int NumberOfWheels { get { return numOfWheels; } set { numOfWheels = value; } } protected string getBrand() { return brand; } protected void setBrand(string brand) => this.brand = brand; protected string getModel() { return model; } protected void setModel(string model) => this.model = model; public string Color { get { return this.color; } set { this.color = value; } } public int Year { get { return year; } set { this.year = value; } //get => year; //set => year = value; }
public void setRadioColor(string color) { radio.setColor(color); } public string getRadioColor() { return radio.getColor(); }
//public static void Main(string[] args) //{ // Vehicle vehicle = new Vehicle("1", "2", "3", 1, 2); // vehicle.numOfWheels = 10; // Console.WriteLine(vehicle.numOfWheels); // Console.ReadLine(); //} }
}
23 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
Yep I found in the end Thank you all for helping me, your conversation helped me to understand few things, so it was blessed anyway. Thank you much!
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
@er🎃 @SpReeD @leowest WinForms is another disgning technology of C#? It's totally newbie with this language
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
Honestly I don't see this
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
Ok I got you both
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
Thank you very much for the help🙏
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
But ok I'll follow what you said
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
For sure I'm starting to get confused 😂
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
For sure it seems like ten times more comfortable than javaFX
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
Directly you mean by coding right?
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
So should I master wpf first and only then to use the design? in order to avoid bugs?
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
Yep I pressed right click on MainWindow.xaml and then designer
94 replies
CC#
Created by Yarden on 10/27/2024 in #help
✅ How do I get to the graphical window (where I can drag and drop tools)
why?
94 replies