Binary in C#: Flags in 10 minutes or less

  Рет қаралды 3,047

IAmTimCorey

IAmTimCorey

Күн бұрын

Пікірлер: 17
@riskeys
@riskeys Ай бұрын
I love this Flag bit feature. Ever since I discover this, I always try to use it whenever it fits the situation like for a “Status” column, which before knowing this I just use plain integer. Anyway, I use power of 2 (1, 2, 4, 8, etc) just cuz it works lol…. Nice video sir as always
@IAmTimCorey
@IAmTimCorey Ай бұрын
Thanks for sharing!
@farzadmf
@farzadmf Ай бұрын
Question: what's the point of [Flags] attribute if we need to manually set them "by hand" ourselves? I thought it should somehow take care of setting them to proper binary values based on their order
@Kar08Mie
@Kar08Mie Ай бұрын
yes, i'm also surprised .NET doesnt manage this automatically for us.
@IAmTimCorey
@IAmTimCorey Ай бұрын
The Flags attribute allows it to be treated as a binary flag rather than an int. That means you can do bitwise operations on the values. It also means that when you do a ToString, it outputs the flag values instead of an int, so “Read, Write” instead of 3. Remember too that you can have an enum variable that has an integer value that isn’t one of the enum options (since it is a combination of two or more values.
@farzadmf
@farzadmf Ай бұрын
@@IAmTimCorey Thanks for the explanation
@camerontangen2957
@camerontangen2957 Ай бұрын
Literally woke up this morning realizing I need to figure out how to use Flags in my own personal project. Thank you!
@IAmTimCorey
@IAmTimCorey Ай бұрын
I am glad it was helpful.
@randlmorales4890
@randlmorales4890 Ай бұрын
What is the highest number of enum values you can use until it becomes better to use a different approach?
@IAmTimCorey
@IAmTimCorey Ай бұрын
You can technically make the enum a long (64 bit), but that’s not really the issue. The issue is practicality. If you get into the 20-item range, you should probably be thinking through your design. It might be time to refactor.
@Ultimate_Luki
@Ultimate_Luki Ай бұрын
Thanks for the video. You should do one for how to check whether a flag is set and how to set it and how to toggle it. For example if you use userAccountControl from AD and a user has a value of 2080, how to check whether its enabled.
@IAmTimCorey
@IAmTimCorey Ай бұрын
These are in the queue.
@princefowzan
@princefowzan Ай бұрын
so putting [Flags] before the enum makes it a flag, here, what is this flags?, a class, a type or what? what is this syntax ?
@halbertwalston
@halbertwalston Ай бұрын
In this usage, "[Flags]" is an Attribute of the enumerator (System.Attributes).
@krccmsitp2884
@krccmsitp2884 Ай бұрын
Instead of shifting (1
@IAmTimCorey
@IAmTimCorey Ай бұрын
Personal preference is fine. For me, I prefer the shorter syntax rather than trying to read the number of zeros.
Binary in C#: Assigning Flags in 10 minutes or less
6:03
IAmTimCorey
Рет қаралды 2,6 М.
Advanced Breakpoints and Tracepoints in C#
22:36
IAmTimCorey
Рет қаралды 6 М.
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 2,1 МЛН
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН
Thank you Santa
00:13
Nadir Show
Рет қаралды 33 МЛН
62. .NET Framework vs .NET Core vs .NET vs .NET Standard vs C#
25:14
10 Important Python Concepts In 20 Minutes
18:49
Indently
Рет қаралды 311 М.
223. Protect Yourself From Layoffs, Downsizing, and Losing Your Job
12:53
How To Use Recursion in C#
19:08
IAmTimCorey
Рет қаралды 10 М.
How to Measure Time Correctly in .NET
9:43
Nick Chapsas
Рет қаралды 48 М.
The Path to C# in 2024
1:03:41
IAmTimCorey
Рет қаралды 102 М.
Every single feature of C# in 10 minutes
9:50
Train To Code
Рет қаралды 152 М.
226. Why You Aren't Landing Your Dream Development Job
15:25
IAmTimCorey
Рет қаралды 3,3 М.
233. 3 Ways To Stand Out From The Crowd in Software Development
17:49
"You're Doing Validation Wrong in .NET" | Code Cop #023
14:44
Nick Chapsas
Рет қаралды 40 М.
Молодой боец приземлил легенду!
01:02
МИНУС БАЛЛ
Рет қаралды 2,1 МЛН