本文整理汇总了C#中CultureInfo类的典型用法代码示例。如果您正苦于以下问题:C# CultureInfo类的具体用法?C# CultureInfo怎么用?C# CultureInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CultureInfo类属于命名空间,在下文中一共展示了CultureInfo类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
CultureInfo MyCultureInfo = new CultureInfo("en-US");
DateTime myDateTime;
DateTime startTime = DateTime.Parse("1:00 PM");
DateTime endTime = DateTime.Parse("3:00 AM");
string inputString = Console.ReadLine();
if (DateTime.TryParseExact(inputString, "h:mm tt", MyCultureInfo, DateTimeStyles.None, out myDateTime))
{
if (myDateTime > startTime || myDateTime < endTime)
{
Console.WriteLine("beer time");
}
else
{
Console.WriteLine("non-beer time");
}
}
else
{
Console.WriteLine("invalid time");
}
}
开发者ID:Moiraines,项目名称:TelerikAcademy,代码行数:25,代码来源:BeerTime.cs
示例2: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Check a random Decimal.");
try
{
Decimal i1 =new decimal( TestLibrary.Generator.GetSingle(-55));
CultureInfo myCulture = new CultureInfo("en-us");
bool actualValue = ((IConvertible)i1).ToBoolean(myCulture);
if (!actualValue)
{
TestLibrary.TestFramework.LogError("001.1", "ToBoolean should return " + actualValue);
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:CheneyWu,项目名称:coreclr,代码行数:25,代码来源:decimaltoboolean.cs
示例3: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify convert byte value when positiveSign is set...");
try
{
string byteString = "plus128";
CultureInfo culture = new CultureInfo("");
NumberFormatInfo numberFormat = culture.NumberFormat;
numberFormat.PositiveSign = "plus";
Byte myByte = Byte.Parse(byteString, NumberStyles.Number, numberFormat);
UInt16 conVertUInt16 = ((IConvertible)myByte).ToUInt16(numberFormat);
if (conVertUInt16 != 128)
{
TestLibrary.TestFramework.LogError("001", "The convert byte is not equal to original!");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception occurs: " + e);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:29,代码来源:byteiconvertibletouint16.cs
示例4: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Convert a random Int16 to String ");
try
{
Int16 i1 = TestLibrary.Generator.GetInt16(-55);
IConvertible Icon1 = (IConvertible)i1;
CultureInfo cultureinfo = new CultureInfo("en-US");
string s1 = Icon1.ToType(typeof(System.String), cultureinfo) as string;
if (s1 != i1.ToString())
{
TestLibrary.TestFramework.LogError("001", "The result is not the value as expected.The random number is :" + i1.ToString());
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:28,代码来源:int16iconvertibletotype.cs
示例5: PosTest3
public bool PosTest3()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest3: Convert UInt64MinValue to string");
try
{
UInt64 i = UInt64.MinValue;
IFormatProvider iFormatProvider = new CultureInfo("fr-FR");
string str = Convert.ToString(i, iFormatProvider);
if (str != i.ToString(iFormatProvider))
{
TestLibrary.TestFramework.LogError("005", "The result is not the value as expected");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:CheneyWu,项目名称:coreclr,代码行数:25,代码来源:converttostring33.cs
示例6: PosTest1
public bool PosTest1()
{
bool retVal = true;
// Add your scenario description here
TestLibrary.TestFramework.BeginScenario("PosTest1: Verify method GetInstance .");
try
{
CultureInfo ci = new CultureInfo("fr-FR");
NumberFormatInfo nfi = NumberFormatInfo.GetInstance(ci);
if (nfi == null)
{
TestLibrary.TestFramework.LogError("001.1", "Method GetInstance Err .");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:28,代码来源:numberformatinfogetinstance.cs
示例7: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Check a single which is -123.");
try
{
Single i1 = (Single)(-123);
CultureInfo myCulture = new CultureInfo("en-us");
int actualValue = ((IConvertible)i1).ToInt32(myCulture);
if (actualValue != (int)(-123))
{
TestLibrary.TestFramework.LogError("002.1", "ToInt32 return failed. ");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:27,代码来源:singletoint32.cs
示例8: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2: Compare two string ");
try
{
string a = "hello";
string b = "aaaaa";
CultureInfo cultureInfo = new CultureInfo("en-US");
CompareInfo comparer = cultureInfo.CompareInfo;
int result = comparer.Compare(b, a);
if (result >= 0)
{
TestLibrary.TestFramework.LogError("003", "The result is not the value as expected");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:27,代码来源:icomparercompare.cs
示例9: Main
static void Main()
{
try
{
Console.WriteLine("Enter dates in format: dd:mm:yyyy");
Console.Write("Enter first date: ");
string firstDate = Console.ReadLine();
Console.Write("Enter second date: ");
string secondDate = Console.ReadLine();
IFormatProvider culture = new CultureInfo("bg");
string format = "dd/mm/yyyy";
DateTime dateOne = DateTime.ParseExact(firstDate, format, culture);
DateTime dateTwo = DateTime.ParseExact(secondDate, format, culture);
int dayOne = dateOne.Day;
int dayTwo = dateTwo.Day;
int result;
if (dayOne > dayTwo)
{
result = dayOne - dayTwo;
}
else
{
result = dayTwo - dayOne;
}
Console.WriteLine("Distance : {0}", result);
}
catch (Exception)
{
Console.WriteLine("Invalid date format !");
Console.WriteLine("Try like the following example : (27.02.2006)");
throw;
}
}
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:33,代码来源:DifferenceBetween2Days.cs
示例10: NegTest1
public bool NegTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("NegTest1: Check a single which is >UInt32.MaxValue.");
try
{
Single i1 = (float)UInt32.MaxValue + 1.0f;
CultureInfo myCulture = new CultureInfo("en-US");
uint actualValue = ((IConvertible)i1).ToUInt32(myCulture);
TestLibrary.TestFramework.LogError("101.1", "ToUInt32 return failed. ");
retVal = false;
}
catch (OverflowException)
{
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("101.2", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:CheneyWu,项目名称:coreclr,代码行数:28,代码来源:singletouint32.cs
示例11: Main
static void Main()
{
/*
Problem 19. Dates from text in Canada
Write a program that extracts from a given text all dates that match the format DD.MM.YYYY.
Display them in the standard date format for Canada.
*/
IFormatProvider culture = new CultureInfo("en-CA", true);
string text = "fgfdgdgd 29.03.2014 29.02.2013 gd dfdg fggggggd 30.04.2013 g g 2.3 33.2.333";
for (int i = 0; i < text.Length - 9; i++)
{
if(char.IsDigit(text[i]))
{
for(int j = 0; j <= 1; j++)
{
string strDate = text.Substring(i, 9 + j);
DateTime date;
if(DateTime.TryParseExact(strDate, "dd.MM.yyyy", culture, DateTimeStyles.None, out date))
{
DateTime dt = date;
Console.WriteLine("{0}.{1}.{2}", date.Day, date.Month, date.Year);
i += 9;
}
}
}
}
}
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:29,代码来源:ExtractDates.cs
示例12: Initialize
public void Initialize(CultureInfo thisCultureInfo, bool checkTranslation = false)
{
if(smartLocWindow != null && !Application.isPlaying && thisCultureInfo != null)
{
if(undoManager == null)
{
// Instantiate Undo Manager
undoManager = new HOEditorUndoManager(this, "Smart Localization - Translate Language Window");
}
if(thisCultureInfo != null)
{
bool newLanguage = thisCultureInfo != this.thisCultureInfo ? true : false;
this.thisCultureInfo = thisCultureInfo;
if(thisLanguageValues == null || thisLanguageValues.Count < 1 || newLanguage)
{
InitializeLanguage(thisCultureInfo, LocFileUtility.LoadParsedLanguageFile(null), LocFileUtility.LoadParsedLanguageFile(thisCultureInfo.Name));
}
}
if(checkTranslation)
{
//Check if the language can be translated
canLanguageBeTranslated = false;
CheckIfCanBeTranslated();
if(translateFromDictionary != null)
{
translateFromDictionary.Clear();
translateFromDictionary = null;
}
}
}
}
开发者ID:wuxin0602,项目名称:Nothing,代码行数:34,代码来源:TranslateLanguageWindow.cs
示例13: PosTest3
public bool PosTest3()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest3: Check a single which is +123.");
try
{
Single i1 = (Single)(+123);
CultureInfo myCulture = new CultureInfo("en-US");
Single actualValue = ((IConvertible)i1).ToSingle(myCulture);
if (actualValue != i1)
{
TestLibrary.TestFramework.LogError("003.1", "ToSingle return failed. ");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("003.2", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:27,代码来源:singletosingle.cs
示例14: Main
static void Main()
{
Console.WriteLine("Inpute time:");
string timeString = Console.ReadLine();
CultureInfo culture = new CultureInfo("en-US");
DateTimeStyles styles = DateTimeStyles.None;
DateTime time;
DateTime startTime = DateTime.Parse("1:00 PM");
DateTime endTime = DateTime.Parse("3:00 AM");
if (DateTime.TryParse(timeString, culture, styles, out time))
{
if (startTime <= time || time < endTime)
{
Console.WriteLine("Beer time");
}
else
{
Console.WriteLine("Non-beer time");
}
}
else
{
Console.WriteLine("Invalid time");
}
}
开发者ID:DeianH94,项目名称:ProgrammingBasicsHomeworks,代码行数:25,代码来源:BeerTime.cs
示例15: PosTest1
public bool PosTest1()
{
bool retVal = true;
const string c_TEST_DESC = "PosTest1: Verify the TextInfo equals original TextInfo. ";
const string c_TEST_ID = "P001";
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
CultureInfo ci = new CultureInfo("en-US");
CultureInfo ci2 = new CultureInfo("en-US");
object textInfo = ci2.TextInfo;
try
{
int originalHC = ci.TextInfo.GetHashCode();
int clonedHC = (textInfo as TextInfo).GetHashCode();
if (originalHC != clonedHC)
{
string errorDesc = "the cloned TextInfo'HashCode should equal original TextInfo's HashCode.";
TestLibrary.TestFramework.LogError("001" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:CheneyWu,项目名称:coreclr,代码行数:32,代码来源:textinfogethashcode.cs
示例16: ApplyNewLanguageAndRefreshPage
protected void ApplyNewLanguageAndRefreshPage(CultureInfo culture)
{
ApplyNewLanguage(culture);
//Refresh the current page to make all control-texts take effect
Response.Redirect(Request.Url.AbsoluteUri);
}
开发者ID:CamilleValley,项目名称:SnipeAgent,代码行数:7,代码来源:PageBases.cs
示例17: PosTest2
public bool PosTest2()
{
bool retVal = true;
const string c_TEST_DESC = "PosTest2: Verify the TextInfo is not same CultureInfo's . ";
const string c_TEST_ID = "P002";
TextInfo textInfoFrance = new CultureInfo("fr-FR").TextInfo;
TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
TestLibrary.TestFramework.BeginScenario(c_TEST_DESC);
try
{
int franceHashCode = textInfoFrance.GetHashCode();
int usHashCode = textInfoUS.GetHashCode();
if (franceHashCode == usHashCode)
{
string errorDesc = "the differente TextInfo's HashCode should not equal. ";
TestLibrary.TestFramework.LogError("003" + " TestId-" + c_TEST_ID, errorDesc);
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004" + " TestId-" + c_TEST_ID, "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:CheneyWu,项目名称:coreclr,代码行数:32,代码来源:textinfogethashcode.cs
示例18: ApplyNewLanguage
private void ApplyNewLanguage(CultureInfo culture)
{
LanguageManager.CurrentCulture = culture;
//Keep current language in session
Session.Add(SESSION_KEY_LANGUAGE, LanguageManager.CurrentCulture);
}
开发者ID:CamilleValley,项目名称:SnipeAgent,代码行数:7,代码来源:PageBases.cs
示例19: PosTest1
//CultureInfo.GetCultureInfo has been removed. Replaced by CultureInfo ctor.
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Check a random single.");
try
{
Single i1 = TestLibrary.Generator.GetSingle(-55);
int expectValue = 0;
if (i1 > 0.5)
expectValue = 1;
else
expectValue = 0;
CultureInfo myCulture = new CultureInfo("en-us");
int actualValue = ((IConvertible)i1).ToInt32(myCulture);
if (actualValue != expectValue)
{
TestLibrary.TestFramework.LogError("001.1", "ToInt32 return failed. ");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.2", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
开发者ID:l1183479157,项目名称:coreclr,代码行数:31,代码来源:singletoint32.cs
示例20: InitializeCulture
protected override void InitializeCulture()
{
HttpCookie CultureCookie = Request.Cookies["ASLang"];
CultureInfo ci;
if (CultureCookie == null)
{
ci = new CultureInfo("ar-JO");
}
else
{
ci = new CultureInfo(CultureCookie.Value);
}
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
base.InitializeCulture();
switch (Page.Culture)
{
case "Arabic (Jordan)":
Page.Theme = "Ar";
break;
default:
Page.Theme = "En";
break;
}
}
开发者ID:samercs,项目名称:ArchiveSystem,代码行数:26,代码来源:UICaltureBase.cs
注:本文中的CultureInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论