本文整理汇总了C#中Dictionary.Last方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Last方法的具体用法?C# Dictionary.Last怎么用?C# Dictionary.Last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StringJoinTestCase
public void StringJoinTestCase()
{
var dictionary = new Dictionary<String, String>
{
{ RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() },
{ RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() }
};
var actual = dictionary.StringJoin();
var expected = "{0}={1}{2}={3}".F( dictionary.First()
.Key,
dictionary.First()
.Value,
dictionary.Last()
.Key,
dictionary.Last()
.Value );
Assert.AreEqual( expected, actual );
actual = dictionary.StringJoin( ",", ";" );
expected = "{0},{1};{2},{3}".F( dictionary.First()
.Key,
dictionary.First()
.Value,
dictionary.Last()
.Key,
dictionary.Last()
.Value );
Assert.AreEqual( expected, actual );
}
示例2: Calculate
public Dictionary<DateTime, decimal> Calculate()
{
var returnDictionary = new Dictionary<DateTime, decimal>();
if (this.signals.Any())
{
returnDictionary.Add(this.signals.ElementAt(0).Date, this.startingEquity);
var count = this.signals.Count();
for (var i = 0; i <= count - 2; i++)
{
var originalSignal = this.signals.ElementAt(i).SignalType;
if (originalSignal == SignalType.TakeProfits)
{
returnDictionary.Add(this.signals.ElementAt(i + 1).Date,
returnDictionary.OrderBy(d => d.Key).Last().Value);
continue;
}
var startTradePrice = this.signals.ElementAt(i).Price;
var finalTradePrice = this.signals.ElementAt(i + 1).Price;
var percentageDifference = (finalTradePrice - startTradePrice)/startTradePrice;
var percentageDifferenceToEquity = originalSignal == SignalType.Buy && percentageDifference > 0 ||
originalSignal == SignalType.Sell && percentageDifference < 0
? Math.Abs(percentageDifference)
: -Math.Abs(percentageDifference);
var newEquityValue = returnDictionary.Last().Value +
(returnDictionary.Last().Value*percentageDifferenceToEquity);
returnDictionary.Add(this.signals.ElementAt(i + 1).Date, newEquityValue);
}
}
return returnDictionary;
}
示例3: Parse_Normal_String
public void Parse_Normal_String()
{
const string attributes = "media:print";
var destination = new Dictionary<string, string>();
HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);
Assert.AreEqual(1, destination.Count);
Assert.AreEqual("print", destination.Last().Value);
Assert.AreEqual("media", destination.Last().Key);
}
示例4: Parse_Delimited_String_With_Comma
public void Parse_Delimited_String_With_Comma()
{
const string attributes = "media:'print, projection'";
var destination = new Dictionary<string, string>();
HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);
Assert.AreEqual(1, destination.Count);
Assert.AreEqual("print, projection", destination.Last().Value);
Assert.AreEqual("media", destination.Last().Key);
}
示例5: Parse_Media_Query
public void Parse_Media_Query()
{
const string attributes = "media:(max-width:560px)";
var destination = new Dictionary<string, string>();
HtmlAttributesStringParser.ParseIntoDictionary(attributes, destination);
Assert.AreEqual(1, destination.Count);
Assert.AreEqual("(max-width:560px)", destination.Last().Value);
Assert.AreEqual("media", destination.Last().Key);
}
示例6: TagCloudService
public TagCloudService(Dictionary<string, int> Tags, int Width, int Height)
{
_Increment = It => It + _SpiralRoom;
_Decrement = It => It - _SpiralRoom;
if (null == Tags || 0 == Tags.Count)
_Die("Argument Exception, No Tags to disorganize");
if (Width < 30 || Height < 30)
_Die("Way too low Width or Height for the cloud to be useful");
_Width = Width;
_Height = Height;
_MainArea = new RectangleF(0, 0, Width, Height);
_MaxEdgeSize = Width >= Height ? Width : Height;
/* Sentinel is a definitely out of bounds point that the spiral normally
* should never reach. */
_SpiralEndSentinel = new PointF(_MaxEdgeSize + 10, _MaxEdgeSize + 10);
var Sorted = from Tag in Tags
orderby Tag.Value descending
select new {Tag.Key, Tag.Value};
_TagsSorted = Sorted.ToDictionary(x => x.Key, x => x.Value);
_LowestWeight = _TagsSorted.Last().Value;
_HighestWeight = _TagsSorted.First().Value;
_Occupied = new List<RectangleF>(_TagsSorted.Count + 4);
WordsSkipped = new Dictionary<string, int>();
ApplyDefaults();
}
示例7: GetBexisRights
internal List<Right> GetBexisRights(string dataBase, Dictionary<int, int> dataSetsMapping)
{
List<Right> bexisRights = new List<Right>();
string datasetQuery = "";
foreach (var dataSetMapping in dataSetsMapping)
{
datasetQuery += "DATASETID = "+ dataSetMapping.Key;
if (dataSetsMapping.Last().Key != dataSetMapping.Key)
datasetQuery += " or ";
}
if (dataSetsMapping.Any())
{
datasetQuery = "where " + datasetQuery + "";
}
// DB query
string mySelectQuery = "SELECT ROLENAME, DATASETID, FOREDIT, APPLICATIONNAME FROM \"PROVIDER\".\"RIGHTS\" "+ datasetQuery;
DB2Connection connect = new DB2Connection(dataBase);
DB2Command myCommand = new DB2Command(mySelectQuery, connect);
connect.Open();
DB2DataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
bexisRights.Add(new Right()
{
RoleName = myReader.GetString(0),
DataSetId = (int)(myReader.GetValue(1)),
CanEdit = myReader.GetString(2)=="N"?false:true
});
}
myReader.Close();
connect.Close();
return bexisRights;
}
示例8: TagCloudService
public TagCloudService(Dictionary<string, int> tags, int width, int height)
{
increment = x => x + spiralRoom;
decrement = x => x - spiralRoom;
if (null == tags || 0 == tags.Count)
die("Argument Exception, No Tags to disorganize");
if (width < 30 || height < 30)
die("Way too low Width or Height for the cloud to be useful");
this.width = width;
this.height = height;
mainArea = new RectangleF(0, 0, width, height);
MaxEdgeSize = width >= height ? width : height;
/* Sentinel is a definitely out of bounds point that the spiral normally
* should never reach. */
spiralEndSentinel = new PointF(MaxEdgeSize + 10, MaxEdgeSize + 10);
var sorted = from tag in tags
orderby tag.Value descending
select new {tag.Key, tag.Value};
tagsSorted = sorted.ToDictionary(x => x.Key, x => x.Value);
lowestWeight = tagsSorted.Last().Value;
highestWeight = tagsSorted.First().Value;
Occupied = new List<RectangleF>(tagsSorted.Count + 4);
WordsSkipped = new Dictionary<string, int>();
ApplyDefaults();
}
示例9: AggregatesDataIntoDictionary
public void AggregatesDataIntoDictionary()
{
var lastReductionTime = new DateTime(2011, 11, 11, 5, 30, 0, 0);
var reduceLevel = new ReduceLevel { Resolution = 5000 };
var sourceAggregationList = new List<MonitorRecord<double>>
{
new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 0, 500), 5, 5),
new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 1, 0), 25, 4),
new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 1, 500), 7, 8),
new MonitorRecord<double>(new DateTime(2011, 11, 11, 5, 30, 40, 0), 3, 3)
};
var destination = new Dictionary<DateTime, IList<MonitorRecord<double>>>();
var aggregater = new RecordReduceAggregate();
var result = aggregater.Aggregate(lastReductionTime, reduceLevel, sourceAggregationList, destination);
Assert.Equal(2, destination.Count());
var firstItem = destination.First();
Assert.Equal(new DateTime(2011, 11, 11, 5, 30, 2, 500), firstItem.Key);
Assert.Equal(3, firstItem.Value.Count);
var lastItem = destination.Last();
Assert.Equal(new DateTime(2011, 11, 11, 5, 30, 42, 500), lastItem.Key);
Assert.Equal(1, lastItem.Value.Count);
}
示例10: ContainsAllKeyTestCase
public void ContainsAllKeyTestCase()
{
var dictionary = new Dictionary<String, String>
{
{ RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() },
{ RandomValueEx.GetRandomString(), RandomValueEx.GetRandomString() }
};
Assert.IsTrue( dictionary.ContainsAllKey( dictionary.First()
.Key,
dictionary.Last()
.Key ) );
Assert.IsFalse( dictionary.ContainsAllKey( dictionary.First()
.Key,
dictionary.Last()
.Key,
"test" ) );
}
示例11: concatLists
//creates a single list of strings from a Dictionary doesnt preserve ItemTypes!
// deprecated
private List<string> concatLists(Dictionary<string,List<string>> tokens)
{
List<string> result = new List<string>();
object last = tokens.Last();
foreach (KeyValuePair<string,List<string>> ol in tokens) {
result.AddRange(ol.Value);
}
return result;
}
示例12: ConvertToJsObject
public static string ConvertToJsObject(Dictionary<string, object> options)
{
var config = new StringBuilder();
config.Append("{");
foreach (var item in options)
{
config.AppendFormat(" {0}: {1}{2} ", item.Key, item.Value, options.Last().Equals(item) ? "" : ",");
}
config.Append("}");
return config.ToString();
}
示例13: GetDictionaryFromSessionWhenStoredInSessionAsSerializedStringShouldReturnTheDictionary
public void GetDictionaryFromSessionWhenStoredInSessionAsSerializedStringShouldReturnTheDictionary()
{
var environment = GetEnvironment();
var expected = new Dictionary<Guid, string>();
expected.Add(Guid.NewGuid(), "Main");
expected.Add(Guid.NewGuid(), "Sub");
_sessionMock.Setup(s => s["testdictionary"]).Returns(JsonConvert.SerializeObject(expected));
var result = environment.GetFromSession<Dictionary<Guid, string>>("testdictionary");
Assert.IsNotNull(result);
Assert.AreEqual(expected.First().Key, result.First().Key);
Assert.AreEqual(expected.Last().Value, result.Last().Value);
}
示例14: ToJson
public static string ToJson(Dictionary<string, string> variables)
{
var builder = new StringBuilder();
builder.AppendLine("{");
var last = variables.Last().Key;
foreach (var variable in variables)
{
var isLast = (variable.Key == last);
int value;
if (int.TryParse(variable.Value, out value))
builder.AppendLineFormat(" \"{0}\":{1}{2}", variable.Key, value, isLast ? string.Empty : ",");
else
builder.AppendLineFormat(" \"{0}\":\"{1}\"{2}", variable.Key, variable.Value, isLast ? string.Empty : ",");
}
builder.Append("}");
return builder.ToString();
}
示例15: GetProfileHistory
public async Task<Dictionary<string, List<MalProfileHistoryEntry>>> GetProfileHistory()
{
var output = new Dictionary<string, List<MalProfileHistoryEntry>>();
var raw = await GetRequestResponse();
if (string.IsNullOrEmpty(raw))
return null;
var doc = new HtmlDocument();
doc.LoadHtml(raw);
foreach (var historyRow in doc.DocumentNode.Descendants("tr"))
{
try
{
//so this is one big table if it contains only on chld it means that it's day/week header so
if (historyRow.ChildNodes.Count == 3)
{
if(historyRow.InnerText.Trim() == " ")
continue;
output.Add(historyRow.InnerText.Trim(), new List<MalProfileHistoryEntry>());
}
else
{
var current = new MalProfileHistoryEntry();
var link = historyRow.Descendants("a").First();
current.Id = int.Parse(link.Attributes["href"].Value.Split('=').Last());
current.IsAnime = link.Attributes["href"].Value.Contains("/anime");
current.WatchedEpisode = int.Parse(historyRow.Descendants("strong").First().InnerText);
current.Date = historyRow.Descendants("td").Last().InnerText; //skip "Edit" button
output.Last().Value.Add(current);
}
}
catch (Exception e)
{
//html
}
}
return output;
}