作者PHANTOMAN (源)
看板C_Sharp
标题[问题] 请教继承问题
时间Sat Dec 26 18:20:18 2009
请教各位前辈一个方法继承的问题,我想要达成的目标如下:
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)
1F:推 dna2me:这行的宣告怪怪的耶 01/14 01:01
2F:→ dna2me:mySonClass myClassTest = new mySonClassTest(); 01/14 01:01
3F:→ dna2me:应该是 mySonClass myClassTest = new mySonClass(); 01/14 01:01
4F:→ dna2me:但是因为你是继承,所以应该是 01/14 01:02
5F:→ dna2me:myFatherClass myClassTest = new mySonClass(); 01/14 01:02
6F:→ dna2me:请板上的强者帮忙看看我有没有错 01/14 01:03