SORU
26 Mart 2009, PERŞEMBE


Göster C eşdeğer Java#

Benim seçtiğim bir anahtar ile bir koleksiyon öğeleri bir liste tutmaya çalışıyorum. Java, sadece aşağıdaki gibi Göster kullanırdım

class Test {
  Map<Integer,String> entities;

  public String getEntity(Integer code) {
    return this.entities.get(code);
  }
}

Orada C bunu yapmanın eşdeğer bir yoldur#? System.Collections.Generic.Hashset karma ve özel bir tür anahtar tanımlamak kullanan yok System.Collections.Hashtable genel bir sınıf değil
System.Collections.Generic.Dictionary get(Key) bir yöntem yok

CEVAP
26 Mart 2009, PERŞEMBE


Senin ihtiyacın yoktu dizin Sözlük,''.

Dictionary<string,string> example = new Dictionary<string,string>();
...
example.Add("hello","world");
...
Console.Writeline(example["hello"]);

Test/değerleri elde etmek için etkili bir yöntem TryGetValue (Earwicker teşekkür ederim:)

if (otherExample.TryGetValue("key", out value))
{
    otherExample["key"] = value   1;
}

Bu yöntem ile hızlı ve özel durum-daha az değerler (varsa) alabilirsiniz.

Kaynaklar:

Dictionary-Keys

Try Get Value

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bigapplemagic

    Bigapplemagi

    22 EYLÜL 2011
  • Myron and Nejusha dance

    Myron and Ne

    2 AĞUSTOS 2012
  • snookie77

    snookie77

    2 Mart 2006