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

  Рет қаралды 216,694

Questpond

Questpond

Күн бұрын

Пікірлер: 56
@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)
@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
@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 .
@nocultist7050
@nocultist7050 3 жыл бұрын
This is a hidden gem of a channel.
@dnskk
@dnskk 9 жыл бұрын
sir const are implicitly static so u need not to put static in front of them
@expertreviews1112
@expertreviews1112 8 жыл бұрын
absolutely fantastic video. goodness me such good explanation. Be Blessed
11 жыл бұрын
Very helpful. Thank you. Never really understood the point of readonly until now.
@HikeThePlanets
@HikeThePlanets 4 жыл бұрын
Thanks so much for explaining that so simply and thoroughly.
@RohanShirodkar29
@RohanShirodkar29 7 ай бұрын
Thanks for sharing this informatational video
@aks-tech-1
@aks-tech-1 7 жыл бұрын
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
@olglez9230
@olglez9230 3 жыл бұрын
Nice one. Very clearly explained with a good example. This may come up on an interview open day!
@pcm0it
@pcm0it 11 жыл бұрын
The static modifier is not allowed in a constant declaration.
@mradosovic
@mradosovic 3 жыл бұрын
Very nice explanation with a good example.
@harshsaxena05
@harshsaxena05 3 жыл бұрын
excellent explanation thank you.
@venkateshpillay3213
@venkateshpillay3213 3 жыл бұрын
Great sir 👌 Thank you
@amolshinde7832
@amolshinde7832 3 жыл бұрын
Very good explanation, thanks
@marklitvin9291
@marklitvin9291 7 жыл бұрын
Very well explained. Thank you!
@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.
@PanikGrafik
@PanikGrafik 2 жыл бұрын
Dont forget that the value IS STILL HELD !!!
@saurabhmahal1354
@saurabhmahal1354 12 жыл бұрын
Great way to tell the difference ...thanks
@rohitjoshi3240
@rohitjoshi3240 3 жыл бұрын
You declare the static Constructor and used the access modifier, which prone to error.
@kavithan1987
@kavithan1987 6 жыл бұрын
Instead of read-only we can use integer right..is their any difference in memory allocation
@sery152
@sery152 5 жыл бұрын
Can you explain the logic of static inline with const and readonly, they have contradictins...
@manjeetnandal1
@manjeetnandal1 5 жыл бұрын
Great sharing! Thanks....
@Albileon
@Albileon 11 жыл бұрын
Really good, thanks.
@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.
@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 2 жыл бұрын
@@tusharghude15 correct! but he not mention that point is important point.
@prateekbhardwaj9943
@prateekbhardwaj9943 8 жыл бұрын
nicely explained
@sandeepadode1
@sandeepadode1 7 жыл бұрын
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.
@ahmadezzat9031
@ahmadezzat9031 6 жыл бұрын
The const is by default static.
@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++.
@ankitsinha007
@ankitsinha007 3 жыл бұрын
A static constructor does not have access modifier
@pankajjha1914
@pankajjha1914 4 жыл бұрын
thnku sir.
@zerosandones7547
@zerosandones7547 3 жыл бұрын
static constructor in IL code is cctor
@MrJonnis13
@MrJonnis13 8 жыл бұрын
Thank you
@yeshyuvi
@yeshyuvi 12 жыл бұрын
its good and thank u
@codewithparveenyadav
@codewithparveenyadav 7 жыл бұрын
useful
@smanputra
@smanputra 11 жыл бұрын
great explanation and examples..
@hlch7774
@hlch7774 2 жыл бұрын
const no need to use static
@lakshmisruthi1342
@lakshmisruthi1342 3 жыл бұрын
I wish I watched this video before attending interview :/
@williamwang2047
@williamwang2047 Жыл бұрын
i think u said wrong, PI should be const, as it never changed......
@semikolon4229
@semikolon4229 6 жыл бұрын
thanks, very useful
@wiepcorbier
@wiepcorbier 5 жыл бұрын
Stop the "you know" please.
@naturebc
@naturebc 2 жыл бұрын
This is one of those things that makes a language worse. More complex for no good reason at all.
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН
REAL or FAKE? #beatbox #tiktok
01:03
BeatboxJCOP
Рет қаралды 18 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Solid Principles Interview Questions in C#
32:33
Questpond
Рет қаралды 9 М.
c# (Csharp) and .NET :- Difference between IEnumerable and IEnumerator.
13:39
.NET Interview Preparation videos
Рет қаралды 497 М.
c# (Csharp):- What is the use of Yield keyword in c# ?
10:35
.NET Interview Preparation videos
Рет қаралды 277 М.
OOP interview questions :- What is the difference between Abstraction and Encapsulation ?
12:34
.NET Interview Preparation videos
Рет қаралды 787 М.
c# (Csharp) threading interview question:- What is thread,background thread and foreground thread ?
12:16
you will never ask about pointers again after watching this video
8:03
It works #beatbox #tiktok
00:34
BeatboxJCOP
Рет қаралды 41 МЛН