What does it means when a method is started using "private"in c#? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What does it means when a method is started using "private"in c#?

Somewhere I've seen method declaration like "private method (args)", what does private means here?

10th Nov 2017, 6:29 PM
Ashutosh Kumar
Ashutosh Kumar - avatar
2 Answers
+ 2
private means that the method used is available for the current class only, and if you use a private variable inside a method it will be restricted to the containing method. Which means that [private] is used to restrict access to the argument/function to the container in example. A method that is private like "private void Test () {}" will be restricted to the class containing it only. A variable that is private inside a method like "private string name;" can only be accessed or changed in the current method.
11th Nov 2017, 4:46 AM
#X#
#X# - avatar
+ 1
when a method is private you can only use it in tgat class ,attempt to use that method outside of that class produces an error
10th Nov 2017, 6:43 PM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar