PhoneNumberFormatter.TryCreate(String, PhoneNumberFormatter) 方法

定义

尝试为给定区域代码创建 PhoneNumberFormatter ,失败时不会引发。

public:
 static void TryCreate(Platform::String ^ regionCode, [Out] PhoneNumberFormatter ^ & phoneNumber);
 static void TryCreate(winrt::hstring const& regionCode, [Out] PhoneNumberFormatter const& & phoneNumber);
public static void TryCreate(string regionCode, out PhoneNumberFormatter phoneNumber);
Public Shared Sub TryCreate (regionCode As String, ByRef phoneNumber As PhoneNumberFormatter)

参数

regionCode
String

Platform::String

winrt::hstring

PhoneNumberFormatter 的区域代码。

phoneNumber
PhoneNumberFormatter

成功后,为请求的区域代码提供新的 PhoneNumberFormatter

失败时,此值为 null

注解

以下代码片段演示如何使用此方法为“BR”区域创建 PhoneNumberFormatter

using Windows.Globalization.PhoneNumberFormatting;

PhoneNumberFormatter currentFormatter = null;

PhoneNumberFormatter.TryCreate("BR", out currentFormatter);
if (currentFormatter != null)
{
    // use the formatter 
}  
else
{
    // formatter could not be created for the given region. 
    // put your fallback logic here.
}

适用于