Share via


방법: 특정 데이터 형식의 데이터 검색

업데이트: 2007년 11월

다음 예제에서는 지정된 형식의 데이터 개체에서 데이터를 검색하는 방법을 보여 줍니다.

예제

설명

다음 예제 코드에서는 GetDataPresent(String) 오버로드를 사용하여 먼저 지정된 데이터 형식을 그대로 또는 자동 변환을 통해 사용할 수 있는지 확인합니다. 지정된 형식을 사용할 수 있으면 GetData(String) 메서드를 사용하여 데이터를 검색합니다.

코드

DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// This particular overload of GetDataPresent looks for both native and auto-convertible 
// data formats.
if (dataObject.GetDataPresent(desiredFormat))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}

예제

설명

다음 예제 코드에서는 GetDataPresent(String, Boolean) 오버로드를 사용하여 먼저 지정된 데이터 형식을 그대로 사용할 수 있는지 확인합니다. 자동 변환 가능 데이터 형식은 필터링됩니다. 지정된 형식을 사용할 수 있으면 GetData(String) 메서드를 사용하여 데이터를 검색합니다.

코드

DataObject dataObject = new DataObject("Some string data to store...");

string desiredFormat = DataFormats.UnicodeText;
bool noAutoConvert = false;
byte[] data = null;

// Use the GetDataPresent method to check for the presence of a desired data format.
// The autoconvert parameter is set to false to filter out auto-convertible data formats,
// returning true only if the specified data format is available natively.
if (dataObject.GetDataPresent(desiredFormat, noAutoConvert))
{
    // If the desired data format is present, use one of the GetData methods to retrieve the
    // data from the data object.
    data = dataObject.GetData(desiredFormat) as byte[];
}

참고 항목

개념

끌어서 놓기 개요

참조

IDataObject

기타 리소스

끌어서 놓기 샘플