本文整理汇总了C#中Dictionary.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.GetValue方法的具体用法?C# Dictionary.GetValue怎么用?C# Dictionary.GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValueTest
public void GetValueTest()
{
IDictionary<String, String> d = new Dictionary<String, String>();
d["Test1"] = "Test";
Assert.AreEqual("Test", d.GetValue("Test1"));
Assert.AreEqual(null, d.GetValue("Test2"));
}
示例2: SVGGradientElement
protected SVGGradientElement(SVGParser xmlImp, Dictionary<string, string> attrList)
{
_attrList = attrList;
_xmlImp = xmlImp;
_stopList = new List<SVGStopElement>();
_id = _attrList.GetValue("id");
_gradientUnits = SVGGradientUnit.ObjectBoundingBox;
if (_attrList.GetValue("gradiantUnits") == "userSpaceOnUse")
{
_gradientUnits = SVGGradientUnit.UserSpaceOnUse;
}
//------
// TODO: It's probably a bug that the value is not innoculated for CaSe
// VaRiAtIoN in GetValue, below:
_spreadMethod = SVGSpreadMethod.Pad;
if (_attrList.GetValue("spreadMethod") == "reflect")
{
_spreadMethod = SVGSpreadMethod.Reflect;
}
else if (_attrList.GetValue("spreadMethod") == "repeat")
{
_spreadMethod = SVGSpreadMethod.Repeat;
}
GetElementList();
}
示例3: GetValueTest
public void GetValueTest()
{
var d = new Dictionary<int?, string> { { 1, "a" } };
AssertSome(d.GetValue(1), "a");
AssertNothing(d.GetValue(2));
AssertNothing(d.GetValue(null));
}
示例4: ReturnsNullableValue
public void ReturnsNullableValue()
{
var dict = new Dictionary<Type, string>() {{typeof(int), "1"}, {typeof(double), "2.0"}};
Assert.Equal("1", dict.GetValue(typeof(int)));
Assert.Equal(null, dict.GetValue(typeof(string)));
}
示例5: SVGCircleElement
public SVGCircleElement(Dictionary<string, string> attrList,
SVGTransformList inheritTransformList,
SVGPaintable inheritPaintable,
SVGGraphics render)
: base(attrList, inheritTransformList, inheritPaintable, render)
{
_cx = new SVGLength(attrList.GetValue("cx"));
_cy = new SVGLength(attrList.GetValue("cy"));
_r = new SVGLength(attrList.GetValue("r"));
}
示例6: SetValue
public void SetValue()
{
IDictionary<string, int> Test = new Dictionary<string, int>();
Test.Add("Q", 4);
Test.Add("Z", 2);
Test.Add("C", 3);
Test.Add("A", 1);
Assert.Equal(4, Test.GetValue("Q"));
Test.SetValue("Q", 40);
Assert.Equal(40, Test.GetValue("Q"));
}
示例7: SVGStopElement
public SVGStopElement(Dictionary<string, string> attrList)
{
_stopColor = new SVGColor(attrList.GetValue("stop-color"));
string temp = attrList.GetValue("offset").Trim();
if(temp != "") {
if(temp.EndsWith("%"))
_offset = float.Parse(temp.TrimEnd(new[] { '%' }), System.Globalization.CultureInfo.InvariantCulture);
else
_offset = float.Parse(temp, System.Globalization.CultureInfo.InvariantCulture) * 100;
}
}
示例8: GetValue
public void GetValue()
{
IDictionary<string, int> Test = new Dictionary<string, int>();
Test.Add("Q", 4);
Test.Add("Z", 2);
Test.Add("C", 3);
Test.Add("A", 1);
Assert.Equal(4, Test.GetValue("Q"));
Assert.Equal(0, Test.GetValue("V"));
Assert.Equal(123, Test.GetValue("B", 123));
}
示例9: SVGEllipseElement
public SVGEllipseElement(Dictionary<string, string> attrList,
SVGTransformList inheritTransformList,
SVGPaintable inheritPaintable,
SVGGraphics render)
: base(attrList, inheritTransformList, inheritPaintable, render)
{
_cx = new SVGLength(attrList.GetValue("cx"));
_cy = new SVGLength(attrList.GetValue("cy"));
_rx = new SVGLength(attrList.GetValue("rx"));
_ry = new SVGLength(attrList.GetValue("ry"));
currentTransformList = new SVGTransformList(attrList.GetValue("transform"));
}
示例10: GetValue
public void GetValue()
{
var d = new Dictionary<int, int>
{
{1, 2}
};
Assert.AreEqual(2, d.GetValue(1, 0));
Assert.AreEqual(0, d.GetValue(2, 0));
Assert.AreEqual(Maybe<int>.Empty, d.GetValue(10));
Assert.AreEqual(2, d.GetValue(1).Value);
}
示例11: SVGLineElement
public SVGLineElement(Dictionary<string, string> attrList,
SVGTransformList inheritTransformList,
SVGPaintable inheritPaintable,
SVGGraphics render)
: base(inheritTransformList)
{
_paintable = new SVGPaintable(inheritPaintable, attrList);
_render = render;
_x1 = new SVGLength(attrList.GetValue("x1"));
_y1 = new SVGLength(attrList.GetValue("y1"));
_x2 = new SVGLength(attrList.GetValue("x2"));
_y2 = new SVGLength(attrList.GetValue("y2"));
}
示例12: Cookie
internal Cookie(RemoteSession session, Dictionary dict) {
_session = session;
try {
_name = dict.GetValue("name", string.Empty);
_value = dict.GetValue("value", string.Empty);
_path = dict.GetValue("path", string.Empty);
_domain = dict.GetValue("domain", string.Empty);
_secure = Convert.ToBoolean(dict.Get("secure", false));
_expiry = Convert.ToDouble(dict.Get("expiry", 0));
} catch (Errors.KeyNotFoundError ex) {
throw new DeserializeException(typeof(Cookie), ex);
} catch (Exception ex) {
throw new SeleniumException(ex);
}
}
示例13: PropertiesFromMap
public static ArchiveProperties PropertiesFromMap(Dictionary<string, string> properties)
{
Contract.Requires(properties != null);
var result = new ArchiveProperties { Name = properties.GetValue("Path") };
if (string.IsNullOrEmpty(result.Name)) {
throw new ArgumentException("Archive properties do not contain path.", nameof(properties));
}
result.Type = Archive.StringToType(properties.GetValue("Type"));
result.Size = SevenZipTools.LongFromString(properties.GetValue("Size"));
result.PhysicalSize = SevenZipTools.LongFromString(properties.GetValue("Physical Size"));
result.TotalPhysicalSize = SevenZipTools.LongFromString(properties.GetValue("Total Physical Size"));
return result;
}
示例14: VarietyPairSurrogate
public VarietyPairSurrogate(VarietyPair vp)
{
Variety1 = vp.Variety1.Name;
Variety2 = vp.Variety2.Name;
var wordPairSurrogates = new Dictionary<WordPair, WordPairSurrogate>();
_wordPairs = vp.WordPairs.Select(wp => wordPairSurrogates.GetValue(wp, () => new WordPairSurrogate(wp))).ToList();
PhoneticSimilarityScore = vp.PhoneticSimilarityScore;
LexicalSimilarityScore = vp.LexicalSimilarityScore;
DefaultSoundCorrespondenceProbability = vp.DefaultSoundCorrespondenceProbability;
_cognateSoundCorrespondenceFrequencyDistribution = new Dictionary<SoundContextSurrogate, Tuple<string[], int>[]>();
foreach (SoundContext lhs in vp.CognateSoundCorrespondenceFrequencyDistribution.Conditions)
{
FrequencyDistribution<Ngram<Segment>> freqDist = vp.CognateSoundCorrespondenceFrequencyDistribution[lhs];
_cognateSoundCorrespondenceFrequencyDistribution[new SoundContextSurrogate(lhs)] = freqDist.ObservedSamples.Select(ngram => Tuple.Create(ngram.Select(seg => seg.StrRep).ToArray(), freqDist[ngram])).ToArray();
}
_cognateSoundCorrespondenceByPosition = new Dictionary<string, List<SoundCorrespondenceSurrogate>>();
foreach (KeyValuePair<FeatureSymbol, SoundCorrespondenceCollection> kvp in vp.CognateSoundCorrespondencesByPosition)
{
string pos;
if (kvp.Key == CogFeatureSystem.Onset)
pos = "onset";
else if (kvp.Key == CogFeatureSystem.Nucleus)
pos = "nucleus";
else
pos = "coda";
_cognateSoundCorrespondenceByPosition[pos] = kvp.Value.Select(corr => new SoundCorrespondenceSurrogate(wordPairSurrogates, corr)).ToList();
}
}
示例15: GetValue_Absent_Empty
public void GetValue_Absent_Empty()
{
var dictiionary = new Dictionary<string, int> { { "A", 1 } };
Option<int> item = dictiionary.GetValue("B");
Assert.False(item.HasValue);
}