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 类。