Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello Sir,
In the Bean File of C# project we define the set and get methods.
But before define this we declare names as a private string.. So why we declare the name as private? Is this for security reason or any other?
Posted 3-Nov-12 8:20am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Bean file in C#?
 
About private access modifier:
private: The type or member can be accessed only by code in the same class or struct.
 
Read all you want to know about all access modifiers here:
MSDN: Access Modifiers (C# Programming Guide)[^]
  Permalink  
Comments
Espen Harlinn at 4-Nov-12 11:38am
   
5'ed!
Sandeep Mewara at 4-Nov-12 11:50am
   
Thanks Espen. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This is not for security. Access modifier does not protect a member from access. With Reflection, anyone can access any members, including private and internal. This is done for the same purpose as all other features of programming languages and systems — to support programming as a human activity, to make programming less tedious and error prone. Access modifiers protect developers from additional mistakes usual when everything is accessible and allowed.
 
—SA
  Permalink  
Comments
Espen Harlinn at 4-Nov-12 11:38am
   
5'ed!
Sergey Alexandrovich Kryukov at 4-Nov-12 11:51am
   
Thank you, Espen.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.

So, if the private variable isn't private, then other classes can get/set the value of that variable. And then the private variable skips the get/set process from the property.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 604
1 thatraja 370
2 OriginalGriff 231
3 Sergey Alexandrovich Kryukov 211
4 kbrandwijk 204
0 OriginalGriff 737
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 505
3 Sergey Alexandrovich Kryukov 405
4 thatraja 370


Advertise | Privacy | Mobile
Web04 | 2.8.140902.1 | Last Updated 3 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100