本文整理汇总了C#中Hashtable.TryGetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.TryGetValue方法的具体用法?C# Hashtable.TryGetValue怎么用?C# Hashtable.TryGetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable.TryGetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mission
/// <summary>
/// Initializes a new instance of the <see cref="Mission"/> class.
/// </summary>
/// <param name="missionData">Hashtable of mission data including expirationDate, missionDuration, assignmentCount and assignments as Hashtables themselves.</param>
public Mission(Hashtable missionData)
{
object value;
if (missionData.TryGetValue("expirationDate", out value))
{
expirationDate = DateTime.FromBinary((Int64)value);
}
else
{
Debug.Log("No expirationDate found");
}
if (missionData.TryGetValue("missionDuration", out value))
{
missionDuration = (int)value;
}
else
{
Debug.Log("No missionDuration found");
}
if (missionData.TryGetValue("assignmentCount", out value))
{
int assignmentCount = (int)value;
assignments = new Dictionary<int, Assignment>();
for (int i = 1; i <= assignmentCount; i++)
{
Hashtable assignmentData = null;
string type = "None";
int seqn = 0;
if (missionData.TryGetValue(i, out value))
{
assignmentData = (Hashtable)value;
}
if (assignmentData.TryGetValue("assignmentType", out value))
{
type = (string)value;
assignmentData.Remove("assignmentType");
}
if (assignmentData.TryGetValue("sequenceNumber", out value))
{
seqn = (int)value;
assignmentData.Remove("sequenceNumber");
}
Assignment a = new Assignment(seqn, type, assignmentData);
assignments.Add(seqn, a);
}
Debug.Log("new mission made containing " + assignments.Count + " assignments");
}
else
{
Debug.Log("No assignmentCount found, not loading any assignments.");
}
}
示例2: Character
/// <summary>
/// Initializes a new instance of the <see cref="Character"/> class. Retrieves the gender and other properties of the character from the Hashtable.
/// </summary>
/// <param name="properties">Properties of the character, stored in a Hashtable</param>
public Character(Hashtable properties)
{
playerProperties = properties;
// Retrieving gender string from playerProperties
object genderObject;
playerProperties.TryGetValue("gender", out genderObject);
gender = genderObject as string;
// Determine the model to load for the character when instantiated.
switch (gender)
{
case "male":
genderModelName = "Characters/CharacterBodyMale";
break;
case "female":
genderModelName = "Characters/CharacterBodyFemale";
break;
default:
Debug.Log("No Gender found for character!");
break;
}
}