Generic set (. NET 2.0)

Source: Internet
Author: User

1. List <t>

To determine whether it is null: The Count attribute;

Determine whether an element is in the list: List. Contains (T item );

Traversal can be used: foreach,;

List clear: List. Clear ();

2. dictionary <T1, T2>

To determine whether it is null: The Count attribute;

Traversal can be used:

// Keyvaluepair <t, k>
Foreach (keyvaluepair <string, int> kV in List)
{
Console. writeline (Kv. Key + kv. value );
}
// Version 3.0 or later
Foreach (VAR item in List)
{
Console. writeline (item. Key + item. value );
}
// Obtain from the key set
Foreach (string key in list. Keys)
{
Console. writeline (Key + list [Key]);
}
// Direct value
Foreach (INT Val in list. values)
{
Console. writeline (VAL );
}
// You must use the for method.
List <string> test = new list <string> (list. Keys );
For (INT I = 0; I <list. Count; I ++)
{
Console. writeline (test [I] + list [test [I]);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.