Re: [問題] 請教繼承問題

看板C_Sharp作者 (抓不住...)時間16年前 (2009/12/26 21:04), 編輯推噓5(502)
留言7則, 5人參與, 最新討論串2/2 (看更多)
※ 引述《PHANTOMAN (源)》之銘言: : 請教各位前輩一個方法繼承的問題,我想要達成的目標如下: : 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(); // 希望寫出來的結果如左方所示; 應該不能幫[,]宣告method吧?? 你的fatherClass已經有計算出最大值的method, 就可以利用它達成 public class mysonClass { .... public double maxValue(byte[,] inByte8) { return base.max(iniByte8); } } : } : // 以下是自己嘗試寫的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; : } : } -- C++是一個好的語言....... 因為你的parent不能訪問你的私處(private), 但是friend可以。。。。。。。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.198.120.23

12/26 23:20, , 1F
感謝大大回答,我想要達到的目的是sonClass.iniByte8
12/26 23:20, 1F

12/26 23:23, , 2F
後方還有屬性與方法選項,例如max與ToString()的功能
12/26 23:23, 2F

12/27 10:41, , 3F
可以為內建的二維陣列加入method嗎?應該不行...
12/27 10:41, 3F

12/27 10:54, , 4F
可以繼承Array類別...內建的陣列應該是繼承自Array Class.
12/27 10:54, 4F

12/27 10:55, , 5F
然後在你的子類別中再添加屬性和方法即可.
12/27 10:55, 5F

12/28 08:39, , 6F
簽名檔說得好
12/28 08:39, 6F

01/08 22:16, , 7F
那C#呢@@a
01/08 22:16, 7F
文章代碼(AID): #1BDWdUSw (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #1BDWdUSw (C_Sharp)