Var Keyword - C# Mastery Course

preview_player
Показать описание
Support me in my journey to giving back to the industry all my knowledge and helping the world with what I do. Spreading knowledge to those who cannot afford an education, and helping those who want to better themselves.

Support what I do and pay for me to survive

Merchandise

My Setup & Recommendations

Live Chat at Discord

Source Code
Рекомендации по теме
Комментарии
Автор

Thanks for the video. Kinda reminds me of the late 1970's when I was in engineering school typing FORTRAN code on punch cards. And one of the first lines of code was to state "IMPLICIT NONE", which was how you specified that FORTRAN shouldn't use its default implicit typing (similar to VAR). So using VAR certainly isn't one of those "newer is better" dogmas that people seem to cherish. It's just another tool, with pros and cons, and it's been around forever. And since this was decades before Intellisense, explicit declarations were almost mandatory for understanding thousands of lines of code written on folding printer paper, since hovering over variables wasn't an option. Personally, in my 45+ years as an Electrical Engineer, writing software in many different languages, I generally avoid the use of VAR, and have always thought is was just another way for lazy coders to justify their practices. Kind of like "hey, I don't need to comment my code because it's written so well that it's obvious what it does". Yeah, right. But I also learned long ago that believing any one practice is the perfect way to do things for everyone 100% of the time is utter nonsense. Do whatever works for you and your specific use-case.

EETechStuff
Автор

Hi, great video!
Are you planning on doing a video on vectors and or plotting graphs in C# ?
I would be really happy if you could go into those topics in one of your videos!

philextreme
Автор

I watch your video on 1.5 speed, Perfect

yyds
Автор

Hi, I am viewing your wpf videos. They are very useful. Videos about unit tests would be very welcomed. Not just a basic tutorial like creating a calculator with TDD, but example how you do it in a big project like the chat application.

DrSteve
Автор

Hi, great content again! Can you post/share your VS settings (if I am not mistaken, one can import/export the settings) and extensions/tools installed? Thanks, keep up the good work!

MyNameIsThoms
Автор

Your videos are perfect, thank you a lot. You should be a teacher on university's.

dariodusper
Автор

Isnt this a bad example of using var? Since its making it less readable and if you accidentally assign the wrong type to a var its harder to find be error. So shouldn't you only use var when its hard to tell what you are assigning or when it can take different types?

Roockert
Автор

Enjoying your course, but have a question about a var to be used as a double, if you want to initialize myDouble as zero, if you use: var myDouble = 0; That will set it to be an int, so is it best to set it to "0.0" or just ".0" or does it not matter, or would you even cast it to double?

GazbertUK
Автор

As a newbie, now I wonder why types exist anyway as "var" is the go-to type for anything. Let's start simple: why does "int" still exist, or "double" or "float"?

angel_machariel
Автор

Hi luke how are U? Thanks for this useful lecture

akhabyfan
Автор

Hi, great course, but today I want to ask you one question!
Now, I learn WPF, based on your WPF course.
I have a problem with 12 video of course, using IoC and Ninject.
When I click button, property changed doesn;t work and the page doesn;t changed.
My question is "How can I solve my problem? Is Ninject work good in 2020? Why Property Changed can't be called?"
Thanks a lot!!

БорисСизов-дь
Автор

When you're a developer on a monolith, strongly typing is definitely the way forward. Purely from a code readability perspective if nothing else.

Ye fine, documentation should be provided etc but to a developer, seeing something like IEnumerable<SomeClass> is much quicker to read at first glance when compared to // This is a collection of SomeClass.

var is great when throwing the code together, but me and my team make a conscious effort to strongly type the variables before they get into git...

Tomatoe
Автор

If you're still using Framework instead of Core:
For those who are seeing the same thing as me, with using var, you have to put it in a method, not just inside a class:
class Example
{
public void PreSuffix()
{
var myByte = 0B0110;
var mySbyte = -0B0110;
var myShort = (short)1;
var myUshort = (ushort)1;

// Whole Numbers
var myInt = 1;
var myUint = (uint)1;
var myLong = 1L;
var myUlong = 1UL;

// Decimal Numbers
var myFloat = 1.1F;
var myDouble = 1.1;
var myDecimal = 1.1M;
}
}

If you just try declaring vars just inside the class, you will get errors.
"The contextual keyword 'var' may only appear within a local variable declaration or in script code"
class Example
{
var myByte = 0B0110;
var mySbyte = -0B0110;

var myShort = (short)1;
var myUshort = (ushort)1;

// Whole Numbers
var myInt = 1;
var myUint = (uint)1;
var myLong = 1L;
var myUlong = 1UL;

// Decimal Numbers
var myFloat = 1.1F;
var myDouble = 1.1;
var myDecimal = 1.1M;
}

mitchell
Автор

I was wondering, I thought using var is a bad habit as it has to be converted in IL, thus using the signed variable would be better overall if we are thinking about code efficiency?

ServantKing
Автор

Variables with type Byte also need an explicit type cast, am I right?

var variable = 0b0101;
Console.WriteLine(value: variable.GetTypeCode()); // prints Int32

var variable = (System.Byte) 0b0101;
Console.WriteLine(value: variable.GetTypeCode()); // prints Byte

TheMadpez
Автор

Man I love you but are you sure about this it sounds like a disaster waiting to happen pretty much goes against a lot of the stuff that I've been taught

MudHoleCreation