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

  Рет қаралды 214,725

Questpond

Questpond

Күн бұрын

Пікірлер: 57
@questpondvideos
@questpondvideos 3 жыл бұрын
30 Important C# Interview Questions : kzbin.info/www/bejne/eHzcn3h4hdacf68 25+ OOPS Interview Questions : kzbin.info/www/bejne/q2qcqHSld893rLM Software Architecture Interview Questions : kzbin.info/www/bejne/d6W3mJaYgbSkg68 20+ SQL Server Interview Questions : kzbin.info/www/bejne/iXbHcnluorh-iZY 10+ Power BI Interview Questions : kzbin.info/www/bejne/eaDdlGyNg6eFqpY 20 MSBI Interview Questions : kzbin.info/www/bejne/hKjCpHt7gNOCi6c SQL Server Joins : kzbin.info/www/bejne/gYXZint7o9mppJo SQL Step by Step - kzbin.info/www/bejne/q3jPl4NvpJyeo7s Angular Step by Step Tutorial for Beginners : kzbin.info/www/bejne/Y2q5lIptgqd3qZo 25 Angular Interview Questions : kzbin.info/www/bejne/Y5vIoKx6f6mmia8 25 Important ASP.NET Interview Questions : kzbin.info/www/bejne/ponQfpejf7p2Zsk 35 Important JavaScript Interview Questions : kzbin.info/www/bejne/kJOXlYOfbKh0hLc 20 MySQL Interview Questions : kzbin.info/www/bejne/b5nJm3Zjd9WMaJI 5 MSBI Interview Questions : kzbin.info/www/bejne/a3abYmiXjaaqj7M 20 PHP Interview Questions : kzbin.info/www/bejne/Z5PTf4avo7qlopo
@zerosandones7547
@zerosandones7547 3 жыл бұрын
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)
@klocugh12
@klocugh12 3 жыл бұрын
You didn't mention one thing about const: Compiler actually writes literal value of const as is when compiling. So there is no variable in memory, just a literal 100 number. It is important when you use it in other assemblies. When you modify it where it's defined, other assemblies will still hold value it had when it was compiled, so they have to be recompiled again!
@expertreviews1112
@expertreviews1112 8 жыл бұрын
absolutely fantastic video. goodness me such good explanation. Be Blessed
@dnskk
@dnskk 8 жыл бұрын
sir const are implicitly static so u need not to put static in front of them
@RohanShirodkar29
@RohanShirodkar29 4 ай бұрын
Thanks for sharing this informatational video
@faisalraufpitafi1396
@faisalraufpitafi1396 6 жыл бұрын
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 .
@HikeThePlanets
@HikeThePlanets 4 жыл бұрын
Thanks so much for explaining that so simply and thoroughly.
@nocultist7050
@nocultist7050 3 жыл бұрын
This is a hidden gem of a channel.
@mradosovic
@mradosovic 3 жыл бұрын
Very nice explanation with a good example.
@harshsaxena05
@harshsaxena05 2 жыл бұрын
excellent explanation thank you.
@pcm0it
@pcm0it 11 жыл бұрын
The static modifier is not allowed in a constant declaration.
@olglez9230
@olglez9230 3 жыл бұрын
Nice one. Very clearly explained with a good example. This may come up on an interview open day!
@amolshinde7832
@amolshinde7832 3 жыл бұрын
Very good explanation, thanks
11 жыл бұрын
Very helpful. Thank you. Never really understood the point of readonly until now.
@questpondvideos
@questpondvideos 4 жыл бұрын
New Announcement from Questpond ".NET(C#) FUNDAMENTALS, .NET COLLECTIONS, GENERICS" Course now available @ 799 /12 $. If Interested visit this Link for Subscription with Questpond www.questpond.com/netc-fundamentals-net-collections-generics/cid22
@venkateshpillay3213
@venkateshpillay3213 2 жыл бұрын
Great sir 👌 Thank you
@marklitvin9291
@marklitvin9291 7 жыл бұрын
Very well explained. Thank you!
@aks-tech-1
@aks-tech-1 6 жыл бұрын
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
@Shakti_Singh_Om
@Shakti_Singh_Om 3 жыл бұрын
Important point here is that constants are by default static. You can use static keyword with Readonly and not with constants.
@sery152
@sery152 5 жыл бұрын
Can you explain the logic of static inline with const and readonly, they have contradictins...
@rjshukla_vlogs
@rjshukla_vlogs 8 жыл бұрын
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 :)
@AachaLagaNa
@AachaLagaNa 8 жыл бұрын
Seems that code is written in text editor not in any fiddler or vs ide.
@rjshukla_vlogs
@rjshukla_vlogs 8 жыл бұрын
But while. Running the application how it is showing the correct output.
@tusharghude15
@tusharghude15 7 жыл бұрын
watch carefully he changed it (at 05:48 u can see suddenly public and static disappeared) ur rgt constants cannot be declared as static coz they are implicitly static u always use const like classname.const_var
@vatansoni6439
@vatansoni6439 7 жыл бұрын
+tushar ghude good
@dineshkumarachari8757
@dineshkumarachari8757 Жыл бұрын
@@tusharghude15 correct! but he not mention that point is important point.
@kavithan1987
@kavithan1987 5 жыл бұрын
Instead of read-only we can use integer right..is their any difference in memory allocation
@naterdanger3919
@naterdanger3919 6 жыл бұрын
Forgive me if this was asked already, but is it necessary to label it constant to begin with? Why/When would we need to do such a thing?
@jvsnyc
@jvsnyc 6 жыл бұрын
It is to protect you against goofy mistakes by yourself or others on your team. If something is logically a compile-time constant (or even readonly) if you try to change it later by mistake you can't. There are also optimizations that can be applied to values known not to change, but that is secondary.
@rohitjoshi3240
@rohitjoshi3240 3 жыл бұрын
You declare the static Constructor and used the access modifier, which prone to error.
@saurabhmahal1354
@saurabhmahal1354 11 жыл бұрын
Great way to tell the difference ...thanks
@rajarajanseeman6758
@rajarajanseeman6758 8 жыл бұрын
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
@AachaLagaNa
@AachaLagaNa 8 жыл бұрын
Seems that code is written in text editor not in any fiddler or vs ide.
@jvsnyc
@jvsnyc 6 жыл бұрын
If it is not clear to anyone, that's right, it can't. Doubly confusing for C++ programmers coming over to C# because in C++ const has a different meaning and does not automatically imply static. In C# it appears const implies static and you can't say both just for fun or to be more clear. In C++ the same thing would be static const, because if you said just const you would get one for each object instance. C# has a readonly keyword that doesn't exist in C++.
@sandeepadode1
@sandeepadode1 6 жыл бұрын
My question is why to read only?A constant is constant right be it at compile time or at run time.Does it have any impact on the program?please help.What exactly is the use of using anyone among them?
@jvsnyc
@jvsnyc 6 жыл бұрын
It is to protect you against goofy mistakes by yourself or others on your team. If something is logically a compile-time constant (or even readonly) if you try to change it later by mistake you can't. There are also optimizations that can be applied to values known not to change, but that is secondary.
@manjeetnandal1
@manjeetnandal1 5 жыл бұрын
Great sharing! Thanks....
@pankajjha1914
@pankajjha1914 4 жыл бұрын
thnku sir.
@PanikGrafik
@PanikGrafik 2 жыл бұрын
Dont forget that the value IS STILL HELD !!!
@Albileon
@Albileon 11 жыл бұрын
Really good, thanks.
@ahmadezzat9031
@ahmadezzat9031 6 жыл бұрын
The const is by default static.
@prateekbhardwaj9943
@prateekbhardwaj9943 8 жыл бұрын
nicely explained
@ankitsinha007
@ankitsinha007 3 жыл бұрын
A static constructor does not have access modifier
@zerosandones7547
@zerosandones7547 3 жыл бұрын
static constructor in IL code is cctor
@MrJonnis13
@MrJonnis13 7 жыл бұрын
Thank you
@yeshyuvi
@yeshyuvi 12 жыл бұрын
its good and thank u
@smanputra
@smanputra 11 жыл бұрын
great explanation and examples..
@williamwang2047
@williamwang2047 10 ай бұрын
i think u said wrong, PI should be const, as it never changed......
@codewithparveenyadav
@codewithparveenyadav 7 жыл бұрын
useful
@semikolon4229
@semikolon4229 6 жыл бұрын
thanks, very useful
@hlch7774
@hlch7774 2 жыл бұрын
const no need to use static
@lakshmisruthi1342
@lakshmisruthi1342 3 жыл бұрын
I wish I watched this video before attending interview :/
@wiepcorbier
@wiepcorbier 5 жыл бұрын
Stop the "you know" please.
@naturebc
@naturebc Жыл бұрын
This is one of those things that makes a language worse. More complex for no good reason at all.
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 28 МЛН
Who’s the Real Dad Doll Squid? Can You Guess in 60 Seconds? | Roblox 3D
00:34
c# (Csharp) and .NET :- Difference between IEnumerable and IEnumerator.
13:39
.NET Interview Preparation videos
Рет қаралды 495 М.
C# Out parameters Vs REF parameters
6:43
.NET Interview Preparation videos
Рет қаралды 284 М.
OOP interview questions :- What is the difference between Abstraction and Encapsulation ?
12:34
.NET Interview Preparation videos
Рет қаралды 784 М.
c# (Csharp):- What is the use of Yield keyword in c# ?
10:35
.NET Interview Preparation videos
Рет қаралды 275 М.
What is the difference between “out” and “ref” parameters?
6:50