作者Cloud (抓不住...)
看板C_Sharp
标题Re: [问题] 请教继承问题
时间Sat Dec 26 21:04:16 2009
※ 引述《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
1F:推 PHANTOMAN:感谢大大回答,我想要达到的目的是sonClass.iniByte8 12/26 23:20
2F:→ PHANTOMAN:後方还有属性与方法选项,例如max与ToString()的功能 12/26 23:23
3F:→ Cloud:可以为内建的二维阵列加入method吗?应该不行... 12/27 10:41
4F:推 horngsh:可以继承Array类别...内建的阵列应该是继承自Array Class. 12/27 10:54
5F:推 horngsh:然後在你的子类别中再添加属性和方法即可. 12/27 10:55
6F:推 scottzz:签名档说得好 12/28 08:39
7F:推 iamso1:那C#呢@@a 01/08 22:16