Condividi tramite


DataObject.GetData Metodo

Definizione

Restituisce i dati in un formato di dati specificato.

Overload

Nome Descrizione
GetData(String)

Restituisce i dati in un formato specificato da una stringa.

GetData(Type)

Restituisce un oggetto dati in un formato specificato da un Type oggetto .

GetData(String, Boolean)

Restituisce un oggetto dati in un formato specificato, convertendo facoltativamente i dati nel formato specificato.

GetData(String)

Restituisce i dati in un formato specificato da una stringa.

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

Parametri

format
String

Stringa che specifica il formato per i dati. Per un set di formati di dati predefiniti, vedere la DataFormats classe .

Valori restituiti

Oggetto che contiene i dati nel formato specificato o null se i dati non sono disponibili nel formato specificato.

Implementazioni

Eccezioni

format è null.

Esempio

Nell'esempio seguente viene usato questo metodo per verificare prima di tutto se è disponibile un formato di dati specificato (in modo nativo o tramite conversione automatica); se il formato specificato è disponibile, l'esempio recupera i dati usando il GetData(String) metodo .

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

Nel codice di esempio seguente viene utilizzato il GetDataPresent(String, Boolean) metodo per verificare prima di tutto se è disponibile un formato di dati specificato in modo nativo (i formati di dati convertibili automaticamente vengono filtrati). Se il formato specificato è disponibile, l'esempio recupera i dati usando il GetData(String) metodo .

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

Vedi anche

Si applica a

GetData(Type)

Restituisce un oggetto dati in un formato specificato da un Type oggetto .

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

Parametri

format
Type

Oggetto Type che specifica il formato per i dati. Per un set di formati di dati predefiniti, vedere la DataFormats classe .

Valori restituiti

Oggetto dati con i dati nel formato specificato o null se i dati non sono disponibili nel formato specificato.

Implementazioni

Eccezioni

format è null.

Vedi anche

Si applica a

GetData(String, Boolean)

Restituisce un oggetto dati in un formato specificato, convertendo facoltativamente i dati nel formato specificato.

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

Parametri

format
String

Stringa che specifica il formato per i dati. Per un set di formati di dati predefiniti, vedere la DataFormats classe .

autoConvert
Boolean

true per tentare di convertire automaticamente i dati nel formato specificato; false per nessuna conversione del formato dati.

Valori restituiti

Oggetto dati con i dati nel formato specificato o null se i dati non sono disponibili nel formato specificato.

Se il autoConvert parametro è true e i dati non possono essere convertiti nel formato specificato o se la conversione automatica è disabilitata (chiamando SetData(String, Object, Boolean) con il autoConvert parametro impostato su false), questo metodo restituisce null.

Implementazioni

Eccezioni

format è Null.

Vedi anche

Si applica a