[問題] 請教繼承問題

看板C_Sharp作者 (源)時間16年前 (2009/12/26 18:20), 編輯推噓1(105)
留言6則, 1人參與, 最新討論串1/2 (看更多)
請教各位前輩一個方法繼承的問題,我想要達成的目標如下: 1. 建立一個class可以在屬性iniByte8中輸入二維byte 2. iniByte8的最大值(方法) 參考了站上幾份文件,但尚未有確定的解答,希望有前輩可以回答 我這個問題,目前也還在找相關資料,感恩。 想要達成的目標為 public static void Main(String[] args) { mySonClass myClassTest = new mySonClassTest(); myClassTest.iniByte8 = new byte[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; myClassTest.iniByte8.GetLength(0); // 請教如何寫出左方GetLength(0)的方法; myClassTest.iniByte8.maxValue(); // 希望寫出來的結果如左方所示; } // 以下是自己嘗試寫的class using System; using System.Collections.Generic; using System.Text; namespace frameGrabber { public class myFatherClass { public double maxValue; public double max(byte[,] inByte8) { // Find maxValue maxValue = 0; for (int y = 0; y < inByte8.GetLength(1); y++) { for (int x = 0; x < inByte8.GetLength(0); x++) { if (inByte8[x, y] > maxValue) maxValue = inByte8[x, y]; } } return maxValue; } } public class mySonClass : myFatherClass { public byte[,] iniByte8; } } -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.230.186 ※ 編輯: PHANTOMAN 來自: 140.112.230.186 (12/26 18:28)

01/14 01:01, , 1F
這行的宣告怪怪的耶
01/14 01:01, 1F

01/14 01:01, , 2F
mySonClass myClassTest = new mySonClassTest();
01/14 01:01, 2F

01/14 01:01, , 3F
應該是 mySonClass myClassTest = new mySonClass();
01/14 01:01, 3F

01/14 01:02, , 4F
但是因為你是繼承,所以應該是
01/14 01:02, 4F

01/14 01:02, , 5F
myFatherClass myClassTest = new mySonClass();
01/14 01:02, 5F

01/14 01:03, , 6F
請板上的強者幫忙看看我有沒有錯
01/14 01:03, 6F
文章代碼(AID): #1BDUDaTR (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1BDUDaTR (C_Sharp)