本文整理匯總了C#中System.AppContext類的典型用法代碼示例。如果您正苦於以下問題:C# AppContext類的具體用法?C# AppContext怎麽用?C# AppContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AppContext類屬於System命名空間,在下文中一共展示了AppContext類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SubstringStartsAt
//引入命名空間
using System;
using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")]
public static class StringLibrary
{
public static int SubstringStartsAt(String fullString, String substr)
{
return fullString.IndexOf(substr, StringComparison.Ordinal);
}
}
示例2: Main
//引入命名空間
using System;
public class Example
{
public static void Main()
{
String value = "The archaeologist";
String substring = "archæ";
int position = StringLibrary.SubstringStartsAt(value, substring);
if (position >= 0)
Console.WriteLine("'{0}' found in '{1}' starting at position {2}",
substring, value, position);
else
Console.WriteLine("'{0}' not found in '{1}'", substring, value);
}
}
輸出:
'archæ' not found in 'The archaeologist'
示例3: SubstringStartsAt
//引入命名空間
using System;
using System.Reflection;
[assembly: AssemblyVersion("2.0.0.0")]
public static class StringLibrary
{
public static int SubstringStartsAt(String fullString, String substr)
{
return fullString.IndexOf(substr, StringComparison.CurrentCulture);
}
}
示例4: AssemblyVersion
//引入命名空間
using System;
using System.Reflection;
[assembly: AssemblyVersion("2.0.0.0")]
public static class StringLibrary
{
public static int SubstringStartsAt(String fullString, String substr)
{
bool flag;
if (AppContext.TryGetSwitch("StringLibrary.DoNotUseCultureSensitiveComparison", out flag) && flag == true)
return fullString.IndexOf(substr, StringComparison.Ordinal);
else
return fullString.IndexOf(substr, StringComparison.CurrentCulture);
}
}
示例5: Main
//引入命名空間
using System;
using System.IO;
using System.Runtime.Versioning;
[assembly:TargetFramework(".NETFramework,Version=v4.6.2")]
public class Example
{
public static void Main()
{
Console.WriteLine(Path.GetDirectoryName("file://c/temp/dirlist.txt"));
}
}
輸出:
Unhandled Exception: System.ArgumentException: The path is not of a legal form. at System.IO.Path.NewNormalizePathLimitedChecks(String path, Int32 maxPathLength, Boolean expandShortPaths) at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) at System.IO.Path.InternalGetDirectoryName(String path) at Example.Main()