Difference Between Constant and ReadOnly in C# | CSharp Interview Questions & Answers

preview_player
Показать описание

See our other Step by Step video series below :-
See our other Step by Step video series below :-

In this video we will try to understand what is the difference between 2 important keywords in c# Constant and readonly.

-----------------------------------------------------------------------------------------------
For more details :-
📱 Mob. No. : +91-9967590707 / +91 7700975156 / +91-22-49786776

Share, Support, Subscribe and Connect us on!!!

#ConstantvsReadOnly #CSharpConstant #C#ReadOnly #C#Concepts #CSharpInterviewQuestions #C#InterviewQuestions&Answers
Рекомендации по теме
Комментарии
Автор

Constants:
Constants based on "consts":
- const fields are called compile-time constants
- an absolute constant
- the value of a const variable is set during the declaration itself
- consts variables SHOULD have a value when declared
- the const's value is stored in the IL code itself

Constants based on "readonly":
- the modifier readonly creates fields, which values cannot be changed once they are assigned.
- don't need to define a value during the declaration itself
(a readonly field cannot be assigned to (except in a constructor or init-only setter of the type in which
the field is defined or a variable initializer))
- readonly fields are called run-time constants
- their values cannot be changed after assignment
- this process(value assignment) happens during the execution of the program (in runtime)

zerosandones
Автор

New Announcement from Questpond ".NET(C#) FUNDAMENTALS, .NET COLLECTIONS, GENERICS" Course now available @ 799 /12 $. If Interested visit this Link for Subscription with Questpond

questpondvideos
Автор

sir const are implicitly static so u need not to put static in front of them

dnskk
Автор

sir Aslam o alikum I am from Karachi Pakistan I like your teaching way Mashallah Mashallah you are perfect teacher and I will share your videos with my friends because I want they should learn .

faisalraufpitafi
Автор

absolutely fantastic video. goodness me such good explanation. Be Blessed

expertreviews
Автор

Very helpful. Thank you. Never really understood the point of readonly until now.

Автор

Thanks so much for explaining that so simply and thoroughly.

HikeThePlanets
Автор

Nice one. Very clearly explained with a good example. This may come up on an interview open day!

olglez
Автор

The static modifier is not allowed in a constant declaration.

pcmit
Автор

Very nice explanation with a good example.

mradosovic
Автор

Thanks for sharing this informatational video

MaximusMotivatvation
Автор

I have one suggestion here. You can brief the topic and then explain the programming. You are good in all the way. I am your paid user

aks-tech-
Автор

Great way to tell the difference ...thanks

saurabhmahal
Автор

Important point here is that constants are by default static. You can use static keyword with Readonly and not with constants.

Shakti_Singh_Om
Автор

Can you explain the logic of static inline with const and readonly, they have contradictins...

sery
Автор

You declare the static Constructor and used the access modifier, which prone to error.

rohitjoshi
Автор

Instead of read-only we can use integer right..is their any difference in memory allocation

kavithan
Автор

Dont forget that the value IS STILL HELD !!!

PanikGrafik
Автор

Hello Sir ji .. Its really nice example but i have 1 question here that we can't have static and const simultaneously ?? it is saying that you cant have static with the const ? Could you please let me know how this happens in your example ?? Thanks you so much for your help :)

rjshukla_vlogs
Автор

Still wondering how would you be able to mark as static in const variable? I see the below error

Error 1 The constant 'xxx.Program.myproconst' cannot be marked static

rajarajanseeman
visit shbcf.ru