C# auto implemented properties

C# auto implemented properties

Bro Code

3 года назад

40,043 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@BroCodez
@BroCodez - 29.06.2021 01:46

using System;

namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// auto-Implemented property = shortcut when no additional logic is required in the property
// you do not have to define a field for a property,
// you only have to write get; and/or set; inside the property

Car car = new Car("Porsche");

Console.WriteLine(car.Model);

Console.ReadKey();
}
}

class Car
{
public String Model {get; set;}

public Car(String model)
{
this.Model = model;
}
}
}

Ответить
@qwertzuwu
@qwertzuwu - 17.10.2023 08:12

bro casually teaches programming for free

Ответить
@FedoraChan
@FedoraChan - 29.08.2023 19:58

goat code

Ответить
@EagleEye404
@EagleEye404 - 16.06.2023 17:46

Public Variable "Model" already can be access with dot . operator . Doesn't require get set, why add get set implementation

Ответить
@Ben-fn6wp
@Ben-fn6wp - 30.04.2023 17:13

Thank you for saving me time when i need to write my tests on a paper!!!

Ответить
@RebecaSantos-wt8cz
@RebecaSantos-wt8cz - 15.03.2023 23:47

It's amazing how easy i could understand this hahahaha i was having such a hard time to understand some c# stuff and his channel really helped.

Ответить
@DrIzaakjohnson
@DrIzaakjohnson - 26.02.2023 10:49

Thanks

Ответить
@DrIzaakjohnson
@DrIzaakjohnson - 26.02.2023 10:49

Helpful

Ответить
@DrIzaakjohnson
@DrIzaakjohnson - 26.02.2023 10:48

Random

Ответить
@user-gx3st2th8q
@user-gx3st2th8q - 10.02.2023 21:16

Reeeeeee

Ответить
@DezzWhat
@DezzWhat - 09.01.2023 23:13

thanks bro

Ответить
@prathameshgaikwad7550
@prathameshgaikwad7550 - 20.12.2022 15:34

Why can't we simply have a public variable then. We might also avoid writing get and set. Can you please explain why auto implementation is preferred over normal public instance variable.

Ответить
@caseyspaulding
@caseyspaulding - 20.12.2022 01:26

Thanks!

Ответить
@_FGTS
@_FGTS - 14.07.2022 01:04

why not just setting Model as a public field?

class Car {
public String Model;
}

Ответить
@fidelitycreate
@fidelitycreate - 16.05.2022 13:37

Hi, I've tried using auto properties to make a read only vairable outside of the class. But when I do, any function within the class is now saying that property is read only... But we're still inside the class??? This seems stupid to me. But I got around it by using regular properties.

[EDIT]
I just learned how to make a read-only auto property and have it still editable inside the class :
public float var { get; private set; } = 0f;
The key was "private set".

Apparently, if you use just "{ get; }" you can only modify the property once in the class' constructor.

Ответить
@triton5457
@triton5457 - 27.03.2022 16:44

taco 🌮

Ответить
@whitedinamo
@whitedinamo - 05.02.2022 17:03

lesson check😇

Ответить
@alysonwilliams6473
@alysonwilliams6473 - 28.08.2021 17:55

very helpful! i got so confused for a second because I was thinking you were going to define the model somewhere else too lol porsche is technically the make, not the model. Anyway, this vid helped a lot!

Ответить
@spartanranger
@spartanranger - 27.08.2021 15:19

Thanks for the video Bro.

Ответить
@satish537
@satish537 - 05.07.2021 13:52

hello BRO BIG FAN FROM INDIA

Ответить