[問題] 請教關於 "public static" 與 "static"
各位站上的高手,不知有誰可以為我解惑。
小弟還是初學者,若問得比較沒sense,請鞭小力一點。
謝謝大家!
= = = = =
請問 "public static void"、"static void"
"public static double"、"static double"
它的差別在哪裡?
我有看了一些資料,還是不容易搞清楚,不知有沒有淺顯易懂的說法。
我目前的認知是:
"static void" 是在定義 "函數(子程式)" 才會用到
"static double" 是在定義 "數值" 或 "矩陣" 才會用到
而 public 所要表達的是存取的權限最大
= = = = = = = =
例如在下面的程式(Main.cs)大綱中,
若把下2列的 public 拿掉會有啥影響?
public static double[] Ii(fu u, int i,int j) ...
public static void GetR() ...
我有試過把 "public static void GetR() ..."
改成 "static void GetR() ..."
可是我發現執行結果好像沒差別
= = = = = = =
我的程式為一個專案裡有2個程式,分別為 Lib.cs 與 Main.cs。
其大綱分別如下:
Lib.cs
using System;
using System.Text;
using System.IO;
namespace XYZ
{
public class my ...
public class fu ...
public class Lib ...
}
Main.cs
using System;
{
class class1:Lib
{
static double AR(int R, double[] err, ref double MErr) ...
static double GCR(fu u, int R) ...
public static double[] Ii(fu u, int i,int j) ...
static void comp_i(fu u, int R) ...
public static void GetR() ...
static void Main(string[] args) ...
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.155.138
→
01/09 12:25, , 1F
01/09 12:25, 1F
→
01/09 12:30, , 2F
01/09 12:30, 2F
→
01/09 12:31, , 3F
01/09 12:31, 3F
→
01/09 12:34, , 4F
01/09 12:34, 4F
→
01/09 22:36, , 5F
01/09 22:36, 5F
→
01/09 22:36, , 6F
01/09 22:36, 6F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
C_Sharp 近期熱門文章
PTT數位生活區 即時熱門文章