当前位置:  开发笔记 > 编程语言 > 正文

这个[字符串键]是什么意思

如何解决《这个[字符串键]是什么意思》经验,为你挑选了1个好方法。

我查看了IRequestCookieCollection程序集中的代码Microsoft.AspNetCore.Http:

  //
  // Summary:
  //     Represents the HttpRequest cookie collection
  [DefaultMember("Item")]
  public interface IRequestCookieCollection : IEnumerable>, IEnumerable
  {
    //
    // Summary:
    //     Gets the value with the specified key.
    //
    // Parameters:
    //   key:
    //     The key of the value to get.
    //
    // Returns:
    //     The element with the specified key, or string.Empty if the key is not present.
    //
    // Exceptions:
    //   T:System.ArgumentNullException:
    //     key is null.
    //
    // Remarks:
    //     Microsoft.AspNetCore.Http.IRequestCookieCollection has a different indexer contract
    //     than System.Collections.Generic.IDictionary`2, as it will return string.Empty
    //     for missing entries rather than throwing an Exception.
    string this[string key] { get; }

    //
    // Summary:
    //     Gets the number of elements contained in the Microsoft.AspNetCore.Http.IRequestCookieCollection.
    //
    // Returns:
    //     The number of elements contained in the Microsoft.AspNetCore.Http.IRequestCookieCollection.
    int Count { get; }
    //
    // Summary:
    //     Gets an System.Collections.Generic.ICollection`1 containing the keys of the Microsoft.AspNetCore.Http.IRequestCookieCollection.
    //
    // Returns:
    //     An System.Collections.Generic.ICollection`1 containing the keys of the object
    //     that implements Microsoft.AspNetCore.Http.IRequestCookieCollection.
    ICollection Keys { get; }

    //
    // Summary:
    //     Determines whether the Microsoft.AspNetCore.Http.IRequestCookieCollection contains
    //     an element with the specified key.
    //
    // Parameters:
    //   key:
    //     The key to locate in the Microsoft.AspNetCore.Http.IRequestCookieCollection.
    //
    // Returns:
    //     true if the Microsoft.AspNetCore.Http.IRequestCookieCollection contains an element
    //     with the key; otherwise, false.
    //
    // Exceptions:
    //   T:System.ArgumentNullException:
    //     key is null.
    bool ContainsKey(string key);
    //
    // Summary:
    //     Gets the value associated with the specified key.
    //
    // Parameters:
    //   key:
    //     The key of the value to get.
    //
    //   value:
    //     The key of the value to get. When this method returns, the value associated with
    //     the specified key, if the key is found; otherwise, the default value for the
    //     type of the value parameter. This parameter is passed uninitialized.
    //
    // Returns:
    //     true if the object that implements Microsoft.AspNetCore.Http.IRequestCookieCollection
    //     contains an element with the specified key; otherwise, false.
    //
    // Exceptions:
    //   T:System.ArgumentNullException:
    //     key is null.
    bool TryGetValue(string key, out string value);
  }

而且无法理解这句话是什么

this[string key]

手段.有人可以解释一下吗.



1> Manfred Radl..:

这是一个索引器.它定义了一个索引属性,可用于通过使用objectName["key"]例如a 来访问对象的集合Dictionary.

实现可能看起来像这样:

string this[string key]
{ 
    get{return _internalDictionary[key];}
}

或这个:

string this[string key]
{ 
    get
    {
        switch(key)
        {
            case "Length":
                return this.Length;
            case "Timeout":
                return this.Timeout.ToString();
            case "Version":
                return "1.5.0";
        }
        return null;
    }
}

推荐阅读
mobiledu2402851203
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有