⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example of traditional class field access.htm

📁 点net代码20个
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Example of Traditional Class Field Access</title>
</head>

<body background="../basic3.gif">

<table border="0" cellspacing="0" width="596">
  <tr>
    <td>
      <p align="center"><font color="#FF0000" size="4"><b>Example of Traditional 
      Class Field Access</b></font></td>
  </tr>
  <tr>
    <td> 
      <p><font color="#0000ff" size="2">using</font><font size="2"> System;<br>
      </font><font color="#0000ff" size="2"><br>
      public</font><font size="2"> </font><font color="#0000ff" size="2">class</font><font size="2"> 
      PropertyHolder<br>
      {<br>
      </font><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;</font><font size="2"> 
      </font><font color="#0000ff" size="2">private</font><font size="2"> </font><font color="#0000ff" size="2">int</font><font size="2"> 
      someProperty = 0;<br>
      <br>
      </font><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;</font><font size="2"> 
      </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">int</font><font size="2"> 
      getSomeProperty()<br>
      &nbsp;&nbsp;&nbsp; {<br>
      </font>&nbsp;&nbsp;&nbsp;<font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;&nbsp; 
      return</font><font size="2"> someProperty;<br>
      &nbsp;&nbsp;&nbsp; }<br>
      </font><font color="#0000ff" size="2"><br>
      &nbsp;&nbsp;&nbsp; public</font><font size="2"> </font><font color="#0000ff" size="2">void</font><font size="2"> 
      setSomeProperty(</font><font color="#0000ff" size="2">int</font><font size="2"> 
      propValue)<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; someProperty = propValue;<br>
      &nbsp;&nbsp;&nbsp; }<br>
      </font><font color="#0000ff" size="2"><br>
      </font><font size="2">}<br>
      </font><font color="#0000ff" size="2"><br>
      public</font><font size="2"> </font><font color="#0000ff" size="2">class</font><font size="2"> 
      PropertyTester<br>
      {<br>
      </font><font color="#0000ff" size="2">&nbsp;&nbsp;&nbsp;</font><font size="2"> 
      </font><font color="#0000ff" size="2">public</font><font size="2"> </font><font color="#0000ff" size="2">static</font><font size="2"> 
      </font><font color="#0000ff" size="2">int</font><font size="2"> Main(</font><font color="#0000ff" size="2">string</font><font size="2">[] 
      args)<br>
      &nbsp;&nbsp;&nbsp; {<br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PropertyHolder propHold = </font><font color="#0000ff" size="2">new</font><font size="2"> 
      PropertyHolder();<br>
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; propHold.setSomeProperty(5);<br>
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(&quot;Property 
      Value: {0}&quot;, propHold.getSomeProperty());<br>
      <br>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font><font color="#0000ff" size="2">return</font><font size="2"> 
      0;<br>
      &nbsp;&nbsp;&nbsp; }<br>
      }</font></td>
  </tr>
  <tr>
    <td>Listing 10-1 shows the traditional method of accessing class fields.&nbsp; 
      The PropertyHolder class has the field we're interested in accessing.&nbsp; 
      It has two methods, getSomeProperty and setSomeProperty.&nbsp; The 
      getSomeProperty method returns the value of the someProperty field.&nbsp; 
      The setSomeProperty method sets the value of the someProperty field.</td>
  </tr>
  <tr>
    <td>The PropertyTester class uses the methods of the PropertyHolder class to 
      get the value of the someProperty field in the PropertyHolder class.&nbsp; 
      The Main method instantiates a new PropertyHolder object, propHold.&nbsp; 
      Next it sets the someMethod of propHold to the value 5 by using the 
      setSomeProperty method.&nbsp; Then the program prints out the property 
      value with a Console.WriteLine method call.&nbsp; The argument used to 
      obtain the value of the property is a call to the getSomeProperty method 
      of the propHold object.&nbsp; It prints out &quot;Property Value: 5&quot; 
      to the console.</td>
  </tr>
  <tr>
    <td>This method of accessing information in a field has been good because it 
      supports the object-oriented concept of encapsulation.&nbsp; If the 
      implementation of someProperty changed from an int type to a byte type, 
      this would still work.&nbsp; Now the same thing can be accomplished much 
      smoother with properties.</td>
  </tr>
</table>

</body>

</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -