c# - Which declaration is better? -


I'll change my C # style in programming (I'm using 'Public Stabilizer' for variables, methods - everything).

My question:

  public square WinSock {public socket sock; Public byte [] data; .....} var data = new byte [2058]; Data = WinSock.data;  

Or this one:

  Private Sector WinSock {Personal Sockets Sock; Private byte [] data; ..... Public byte [] getdata () ({return data;}}} WinSock ws = new WinSock (); Var data = new byte [2058]; data = ws.getdata ();  < In both cases, data and sock variables can be accessed from other sections. 

Which of the two statements is better?

< P>

In the object-oriented programming, we explain the variables in classes and only the ones outside the class

Name your properties with an initial capital character, and instead of a method instead of a data member, i.e. instead of data getdata .

  public class WinSock {personal socket _ socket; private byte [] _data; public socket socket {get {return_socket;}} public byte [] Data {get {return _data;}}}  

(One way to name the private member variable is to use an underscore. Other conventions are commonly used, but the important thing is to select and stick to one.)

C # 3 also has a shortcut syntax for properties:

  public class WinSock {public socket socket {get; Private set; } Byte [] data {get; Private set; }}  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -