本文整理汇总了C#中Dictionary.Get方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Get方法的具体用法?C# Dictionary.Get怎么用?C# Dictionary.Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: get_on_dictionary
public void get_on_dictionary()
{
var d = new Dictionary<string, string> { { "a", "hello" } };
d.Get("a").MustHaveValue().Should().Be("hello");
d.Get("b").Should().Be(Maybe<string>.None);
}
示例2: GetTest
public void GetTest()
{
var dict = new Dictionary<string, string>();
dict.Add("b", "b");
Expect(dict.Get("a"), EqualTo(string.Empty));
Expect(dict.Get("b"), EqualTo("b"));
}
示例3: ShouldBeAbleToInitializeBagWithSeveralObjects
public void ShouldBeAbleToInitializeBagWithSeveralObjects()
{
var url = new Url("/1");
var identity = new GenericIdentity("name");
var bag = new Dictionary<string, object>();
bag.Add(identity).Add(url);
Assert.That(bag.Get(typeof(GenericIdentity)), Is.EqualTo(identity));
Assert.That(bag.Get(typeof(Url)), Is.EqualTo(url));
}
示例4: ShouldBeAbleToInitializeBagWithSeveralObjectsWithExplicitTypes
public void ShouldBeAbleToInitializeBagWithSeveralObjectsWithExplicitTypes()
{
var url = new Url("/1");
var identity = new GenericIdentity("name");
var bag = new Dictionary<string, object>();
bag.Add<GenericIdentity>("first", identity);
bag.Add<Url>("second", url);
Assert.That(bag.Get<GenericIdentity>("first"), Is.EqualTo(identity));
Assert.That(bag.Get<Url>("second"), Is.EqualTo(url));
}
示例5: TestMiscDictionaryGet
public void TestMiscDictionaryGet()
{
string key0 = "Blinky";
var dict = new Dictionary<string, int>() { { key0, 42 } };
int value0 = 0;
dict.Get(key0, v => { value0 = v; return true; }, () => value0 = 0);
Assert.Equal(42, value0);
dict.Get(key0, v => { value0 = v; return false; }, () => value0 = 0);
Assert.Equal(0, value0);
}
示例6: Cookie
internal Cookie(RemoteSession session, Dictionary dict) {
_session = session;
try {
_name = (string)dict["name"];
_value = (string)dict["value"];
_path = (string)dict.Get("path", null);
_domain = (string)dict.Get("domain", null);
_expiry = (int?)dict.Get("expiry", null);
_secure = (bool)dict.Get("secure", false);
} catch (Errors.KeyNotFoundError ex) {
throw new DeserializeException(typeof(Cookie), ex);
}
}
示例7: GetTest
public void GetTest()
{
var dict = new Dictionary<int, string>
{
[1] = "one",
[2] = "two"
};
Assert.AreEqual("one", dict.Get(1));
Assert.AreEqual("two", dict.Get(2));
Assert.AreEqual(null, dict.Get(3));
Assert.AreEqual(string.Empty, dict.Get(3, string.Empty));
dict = null;
Assert.AreEqual(null, dict.Get(1));
}
示例8: 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);
}
}
示例9: InternalGetAnagrams
private IEnumerable<string> InternalGetAnagrams(Dictionary<char, int> tiles, List<string> path, Node root,
int minLength, int minWordLength)
{
if (final && depth >= minWordLength)
{
var word = string.Join("", path);
var length = word.Replace(" ", "").Length;
if (length >= minLength)
yield return word;
using (new Guard(() => path.Push(" "), path.Pop))
{
foreach (var anagram in root.InternalGetAnagrams(tiles, path, root, minLength, minWordLength))
yield return anagram;
}
}
foreach (var child in children)
{
var l = child.Key;
var count = tiles.Get(l);
if (count == 0)
continue;
using (new Guard(() => tiles[l] = count - 1, () => tiles[l] = count))
using (new Guard(() => path.Push(l.ToString()), path.Pop))
{
var node = child.Value;
foreach (var anagram in node.InternalGetAnagrams(tiles, path, root, minLength, minWordLength))
yield return anagram;
}
}
}
示例10: GenerateUrlFromTemplate
private static string GenerateUrlFromTemplate(string template, Dictionary<string, object> routeValues)
{
var tokens = tokensCache.Get(template);
if (tokens == null)
{
tokens = template.BraceTokenize().ToArray();
tokensCache[template] = tokens;
}
var builder = new StringBuilder();
foreach (var token in tokens)
{
if (token is BraceTokenizer.Literal)
{
builder.Append(token.Literal);
}
else
{
var id = token.VariableId;
var value = routeValues.Get(id);
builder.Append(value);
routeValues.Remove(id);
}
}
return builder.ToString();
}
示例11: GetAnagrams
public IEnumerable<string> GetAnagrams(string letters, int minWordLength)
{
var counters = new Dictionary<char, int>();
foreach (var l in letters)
counters[l] = counters.Get(l) + 1;
return InternalGetAnagrams(counters, new List<string>(), this, letters.Length, minWordLength);
}
示例12: Get
public void Get()
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
string key = "a";
string value = "myValue";
string result = null;
result = dictionary.Get(key);
Assert.IsNull(result);
dictionary.Add(key, value);
result = dictionary.Get(key);
Assert.AreEqual(value, result);
dictionary = null;
result = dictionary.Get(key);
Assert.IsNull(result);
}
示例13: _execSync
/// <summary>
/// Executes command synchronously
/// </summary>
/// <param name="cmd"></param>
/// <param name="args"></param>
/// <returns></returns>
public Context _execSync(string cmd, string[] args, Dictionary<string, object> opts)
{
Context context = new Context();
if (opts != null)
{
context.setEncoding(opts.Get<string>("encoding"));
}
context.execute(cmd, args);
return context;
}
示例14: _execFile
/// <summary>
/// Executes s file and runs a callback
/// </summary>
/// <param name="cmd"></param>
/// <param name="args"></param>
/// <param name="opts"></param>
/// <param name="callbackId"></param>
/// <returns></returns>
public Context _execFile(string cmd, string[] args, Dictionary<string, object> opts, string exitCallbackId)
{
Context context = new Context();
if (opts != null) {
context.setEncoding(opts.Get<string>("encoding"));
}
context.exitCallbackId = exitCallbackId;
context.start(cmd, args);
return context;
}
示例15: PrintGNU
public static void PrintGNU( string GNU,
IEnumerable<Results> Results, IEnumerable<int> CompLimitTicks,
IEnumerable<string> Algs, IEnumerable<string> Files)
{
if ( !Directory.Exists( GNU ) ) {
Directory.CreateDirectory( GNU );
} else {
throw new ArgumentException( "GNU Folder Exists" );
}
Dictionary<string, double> DStarSol = new Dictionary<string, double>( );
foreach ( string f in Files ) {
var DSol = Results.First( r => r.Algorithm.Equals( "D*Lite" ) &&
f.Equals( r.File ) );
DStarSol.Add( f, DSol.SubOptimality );
}
int NumFiles = Files.Count( );
int Inc = 1; // (int)( NumFiles*0.05 );
Files = Files.OrderBy( x => DStarSol.Get( x ) );
foreach ( string a in Algs ) {
TextWriter W = new StreamWriter( new FileStream( GNU + "/" + a.Replace( "*", "Star" ),
FileMode.CreateNew, FileAccess.Write ) );
System.Console.Out.WriteLine( "Alg " + a );
foreach ( int clt in CompLimitTicks ) {
for ( int i = 0 ; i< NumFiles ; i += Inc ) {
var FilesSet = new HashSet<string>( Files.Skip( i ).Take( Inc ) );
List<double> Difficulties = new List<double>( );
foreach ( var F in FilesSet ) {
double d;
if ( !DStarSol.TryGetValue( F, out d ) ) {
throw new ArgumentException( "D* Solution Missing" );
}
Difficulties.Add( d );
}
double Difficulty = Difficulties.Average( );
var all = ( from r in Results
where a.Equals( r.Algorithm ) &&
FilesSet.Contains( r.File ) && clt == r.ComputationLimit
select r );
if ( all.Any( ) ) {
double AvgSubOpt = all.Select( x => x.SubOptimality ).Average( );
W.WriteLine( a + ", " + clt + ", " + AvgSubOpt + ", " + Difficulty );
W.Flush( );
}
}
W.WriteLine( );
W.Flush( );
}
W.WriteLine( );
W.Flush( );
W.Close( );
}
}