DataObject.GetFormats 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回格式清單,這個資料物件中的資料是以這些格式儲存,或是可以轉換成這些格式。
多載
GetFormats() |
傳回格式清單,這個資料物件中的資料是以這些格式儲存,或是可以轉換成這些格式。 |
GetFormats(Boolean) |
傳回這個資料物件中的資料在儲存時所使用之格式的清單。
|
GetFormats()
傳回格式清單,這個資料物件中的資料是以這些格式儲存,或是可以轉換成這些格式。
public:
virtual cli::array <System::String ^> ^ GetFormats();
public string[] GetFormats ();
abstract member GetFormats : unit -> string[]
override this.GetFormats : unit -> string[]
Public Function GetFormats () As String()
傳回
String[]
字串陣列,其中每個字串都指定這個資料物件所支援之格式的名稱。
實作
範例
下列範例會使用這個方法來取得字串陣列,表示資料物件中可用的所有資料格式, (原生和自動轉換) 。
DataObject dataObject = new DataObject("Some string data to store...");
// Get an array of strings, each string denoting a data format
// that is available in the data object. This overload of GetDataFormats
// returns all available data formats, native and auto-convertible.
string[] dataFormats = dataObject.GetFormats();
// Get the number of data formats present in the data object, including both
// auto-convertible and native data formats.
int numberOfDataFormats = dataFormats.Length;
// To enumerate the resulting array of data formats, and take some action when
// a particular data format is found, use a code structure similar to the following.
foreach (string dataFormat in dataFormats)
{
if (dataFormat == DataFormats.Text)
{
// Take some action if/when data in the Text data format is found.
break;
}
else if(dataFormat == DataFormats.StringFormat)
{
// Take some action if/when data in the string data format is found.
break;
}
}
Dim dataObject As New DataObject("Some string data to store...")
' Get an array of strings, each string denoting a data format
' that is available in the data object. This overload of GetDataFormats
' returns all available data formats, native and auto-convertible.
Dim dataFormats() As String = dataObject.GetFormats()
' Get the number of data formats present in the data object, including both
' auto-convertible and native data formats.
Dim numberOfDataFormats As Integer = dataFormats.Length
' To enumerate the resulting array of data formats, and take some action when
' a particular data format is found, use a code structure similar to the following.
For Each dataFormat As String In dataFormats
If dataFormat = System.Windows.DataFormats.Text Then
' Take some action if/when data in the Text data format is found.
Exit For
ElseIf dataFormat = System.Windows.DataFormats.StringFormat Then
' Take some action if/when data in the string data format is found.
Exit For
End If
Next dataFormat
備註
如需一組預先定義的資料格式,請參閱 DataFormats 類別。
適用於
GetFormats(Boolean)
傳回這個資料物件中的資料在儲存時所使用之格式的清單。
Boolean
旗標指出是否同時納入資料可自動轉換到的格式。
public:
virtual cli::array <System::String ^> ^ GetFormats(bool autoConvert);
public string[] GetFormats (bool autoConvert);
abstract member GetFormats : bool -> string[]
override this.GetFormats : bool -> string[]
Public Function GetFormats (autoConvert As Boolean) As String()
參數
- autoConvert
- Boolean
true
表示擷取這個資料物件中的資料在儲存時所使用的所有格式,或所有其可轉換到的格式。false
則表示只擷取這個資料物件中的資料在儲存時所使用的格式。
傳回
String[]
字串陣列,其中每個字串都指定這個資料物件所支援之格式的名稱。
實作
範例
下列範例會使用這個方法來取得字串陣列,表示只有資料物件中可用的資料格式, (自動轉換的資料格式會篩選) 。
DataObject dataObject = new DataObject("Some string data to store...");
// Get an array of strings, each string denoting a data format
// that is available in the data object. This overload of GetDataFormats
// accepts a Boolean parameter inidcating whether to include auto-convertible
// data formats, or only return native data formats.
string[] dataFormats = dataObject.GetFormats(false /* Include auto-convertible? */);
// Get the number of native data formats present in the data object.
int numberOfDataFormats = dataFormats.Length;
// To enumerate the resulting array of data formats, and take some action when
// a particular data format is found, use a code structure similar to the following.
foreach (string dataFormat in dataFormats)
{
if (dataFormat == DataFormats.Text)
{
// Take some action if/when data in the Text data format is found.
break;
}
}
Dim dataObject As New DataObject("Some string data to store...")
' Get an array of strings, each string denoting a data format
' that is available in the data object. This overload of GetDataFormats
' accepts a Boolean parameter inidcating whether to include auto-convertible
' data formats, or only return native data formats.
Dim dataFormats() As String = dataObject.GetFormats(False) ' Include auto-convertible?
' Get the number of native data formats present in the data object.
Dim numberOfDataFormats As Integer = dataFormats.Length
' To enumerate the resulting array of data formats, and take some action when
' a particular data format is found, use a code structure similar to the following.
For Each dataFormat As String In dataFormats
If dataFormat = System.Windows.DataFormats.Text Then
' Take some action if/when data in the Text data format is found.
Exit For
End If
Next dataFormat
備註
如需一組預先定義的資料格式,請參閱 DataFormats 類別。