Microsoft Visual Studio .NET (Visual C# 혹은 Visual Basic .NET)에서 어레이로부터 어떻게 어레이를 빼낼수 있습니까?



주요한 소프트웨어:
주요한 소프트웨어 버전: 7.0
문제가 해결된 소프트웨어 버전:
부차적인 소프트웨어: N/A

문제점: 저는 2차원 어레이(예를들면 멀티채널 DAQmx 수집에 의해서 구한 것)가 있고, 그것을 각각의 채널로 분리해야할 필요가 있습니다. 이 어레이로부터 각각의 채널로 어떻게 분리할수 있을까요?

솔루션: Buffer 클레스를 사용하십시요.(더 자세한 정보는 아래 링크를 참조하십시요) 이것은 고객님이 효율적으로 ints, double 등의 데이터 타입으로 어레이 밖으로 복사할수 있습니다. 아래의 한부분의 코드는 열의 인덱스 값으로 채널을 빼낸 것입니다. 이코드는 double의 2차원 어레이에 대한 것입니다.


[C#]

private double[] arraySubset(double[,] array, int row)
{
if (array == null) //check if array is empty
throw new ArgumentNullException();

//check for correct array dimentions and whether row is valid
if ( array.Rank < 2 || row < 0 || row > array.GetLength(0) )
throw new ArgumentException();

//get number of columns
int column = array.GetLength(1);

//Allocate a new array
double[] data = new double[column];

//get element size. In the case of a double, this is 8 bytes.
int elementSize = System.Runtime.InteropServices.Marshal.SizeOf(array.GetType().GetElementType());

//Copy bytes from the array
Buffer.BlockCopy(array,row * elementSize * column,data,0,elementSize*column);

return data;

}


관련 링크: MSDN: Buffer Class

첨부:





리포트 날짜: 11/05/2003
마지막 업데이트: 03/29/2005
문서 번호: 334B9O5B