本文整理汇总了C#中System.Collections.Hashtable.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.GetValueOrDefault方法的具体用法?C# Hashtable.GetValueOrDefault怎么用?C# Hashtable.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.GetValueOrDefault方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_get_bool_from_hashtable
public void can_get_bool_from_hashtable()
{
var table = new Hashtable { { "app id", "true" } };
var value = table.GetValueOrDefault<bool>("app id");
Expect(value, Is.True);
}
示例2: get_string_from_hashtable_when_default_is_provided
public void get_string_from_hashtable_when_default_is_provided()
{
var table = new Hashtable { { "app id", "abc123" } };
var value = table.GetValueOrDefault("app id", "abracadabra");
Expect(value, Is.EqualTo("abc123"));
}
示例3: can_get_default_string_from_hashtable
public void can_get_default_string_from_hashtable()
{
var table = new Hashtable { { "app id", "abc123" } };
var value = table.GetValueOrDefault("cat id", "Frank");
Expect(value, Is.EqualTo("Frank"));
}
示例4: get_null_string_from_hashtable_for_missing_value
public void get_null_string_from_hashtable_for_missing_value()
{
var table = new Hashtable { { "app id", "abc123" } };
var value = table.GetValueOrDefault<string>("cat id");
Expect(value, Is.Null);
}
示例5: can_get_default_bool_from_hashtable
public void can_get_default_bool_from_hashtable()
{
var value = true;
var table = new Hashtable { { "app id", "abc123" } };
value = table.GetValueOrDefault("Allow Windows Live Writer", value);
Expect(value, Is.True);
}
示例6: get_bool_from_hashtable_when_default_is_provided
public void get_bool_from_hashtable_when_default_is_provided()
{
var table = new Hashtable { { "app id", "true" } };
var value = table.GetValueOrDefault("app id", false);
Expect(value, Is.True);
}
示例7: can_get_empty_string_rather_than_default
public void can_get_empty_string_rather_than_default()
{
var dictionary = new Hashtable { { "question", string.Empty } };
var value = dictionary.GetValueOrDefault("question", "yes");
Expect(value, Is.Empty);
}
示例8: can_get_null_value_rather_than_default
public void can_get_null_value_rather_than_default()
{
var dictionary = new Hashtable { { "question", null } };
var value = dictionary.GetValueOrDefault("question", "yes");
Expect(value, Is.Null);
}
示例9: can_get_timespan_with_custom_converter
public void can_get_timespan_with_custom_converter()
{
var collection = new Hashtable { { "length", "1:10:10" } };
var value = collection.GetValueOrDefault("length", TimeSpan.Parse);
Expect(value, Is.EqualTo(TimeSpan.FromSeconds(4210)));
}
示例10: get_bool_with_custom_converter_from_hashtable
public void get_bool_with_custom_converter_from_hashtable()
{
var table = new Hashtable { { "allow", "on" } };
var value = table.GetValueOrDefault(
"allow",
v =>
{
bool allowed;
if (!bool.TryParse(v, out allowed))
{
allowed = v.Equals("on", StringComparison.Ordinal);
}
return allowed;
});
Expect(value, Is.True);
}
示例11: get_false_from_hashtable_for_missing_value
public void get_false_from_hashtable_for_missing_value()
{
var table = new Hashtable { { "app id", "abc123" } };
var value = table.GetValueOrDefault<bool>("Allow Windows Live Writer");
Expect(value, Is.False);
}