当前位置: 首页>>代码示例>>C#>>正文


C# Hashtable.TryGetValue方法代码示例

本文整理汇总了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.");
        }
    } 
开发者ID:Solestis,项目名称:SpyGameUnity5,代码行数:58,代码来源:Mission.cs

示例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;
        }
    } 
开发者ID:Solestis,项目名称:SpyGameUnity5,代码行数:27,代码来源:Character.cs


注:本文中的Hashtable.TryGetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。