通过


DataObject.GetData 方法

定义

以指定的数据格式返回数据。

重载

名称 说明
GetData(String)

以字符串指定的格式返回数据。

GetData(Type)

以对象指定的 Type 格式返回数据对象。

GetData(String, Boolean)

以指定格式返回一个数据对象,可以选择将数据转换为指定的格式。

GetData(String)

以字符串指定的格式返回数据。

public:
 virtual System::Object ^ GetData(System::String ^ format);
public object GetData(string format);
public object? GetData(string format);
abstract member GetData : string -> obj
override this.GetData : string -> obj
Public Function GetData (format As String) As Object

参数

format
String

一个字符串,指定数据的格式。 有关一组预定义的数据格式,请参阅该 DataFormats 类。

返回

一个对象,该对象包含指定格式的数据,或者 null 如果数据以指定格式不可用。

实现

例外

formatnull

示例

以下示例使用此方法首先检查指定的数据格式是否可用(本机还是通过自动转换):如果指定的格式可用,该示例将使用 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[];
}
Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim data() As Byte = Nothing

' 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) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If

以下示例代码使用 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[];
}
Dim dataObject As New DataObject("Some string data to store...")

Dim desiredFormat As String = DataFormats.UnicodeText
Dim noAutoConvert As Boolean = False
Dim data() As Byte = Nothing

' 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) Then
    ' If the desired data format is present, use one of the GetData methods to retrieve the
    ' data from the data object.
    data = TryCast(dataObject.GetData(desiredFormat), Byte())
End If

另请参阅

适用于

GetData(Type)

以对象指定的 Type 格式返回数据对象。

public:
 virtual System::Object ^ GetData(Type ^ format);
public object GetData(Type format);
public object? GetData(Type format);
abstract member GetData : Type -> obj
override this.GetData : Type -> obj
Public Function GetData (format As Type) As Object

参数

format
Type

一个 Type ,指定数据的格式。 有关一组预定义的数据格式,请参阅该 DataFormats 类。

返回

具有指定格式的数据对象,或者 null 数据以指定格式不可用。

实现

例外

formatnull

另请参阅

适用于

GetData(String, Boolean)

以指定格式返回一个数据对象,可以选择将数据转换为指定的格式。

public:
 virtual System::Object ^ GetData(System::String ^ format, bool autoConvert);
public object GetData(string format, bool autoConvert);
public object? GetData(string format, bool autoConvert);
abstract member GetData : string * bool -> obj
override this.GetData : string * bool -> obj
Public Function GetData (format As String, autoConvert As Boolean) As Object

参数

format
String

一个字符串,指定数据的格式。 有关一组预定义的数据格式,请参阅该 DataFormats 类。

autoConvert
Boolean

true 尝试将数据自动转换为指定格式; false 不进行数据格式转换。

返回

具有指定格式的数据对象,或者 null 数据以指定格式不可用。

如果参数是且无法将数据转换为指定格式,或者禁用自动转换(通过调用参数设置为 <a0/>),此方法将返回。

实现

例外

formatnull

另请参阅

适用于