共用方式為


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.
}

適用於