Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 06:07

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#]ArrayList

Discussion on [C#]ArrayList within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 35
Join Date: Jun 2012
Posts: 1,126
Received Thanks: 43
[C#]ArrayList

Ich hätte da mal eine frage zu der ArrayList in C#

Und zwar ich möchte gerne in ihr String suchen jedoch wenn sie 1000 oder mehr inhalte hat dauert das sehr lange

Code:
int anzahl = arra.Count;
            for(int i = 0;i < anzahl;i++)
            {
                if (arra[i].ToString() == "h")
                {
                    richtig = true;
                }
                else
                {
                    richtig = false;
                }
            }
gibt es eine schneller methote als diese?
danke schon mal für die Hilfe
master_oli is offline  
Old 11/05/2012, 08:11   #2
 
Naworia's Avatar
 
elite*gold: 12
Join Date: Aug 2011
Posts: 455
Received Thanks: 418
I think you are making hangman or something like this.

It's no problem that your script is long or short. But I can show you example shorter:
Code:
char[] arra = new char[50];
bool richtig = false;
string mytext = "hellboy";
arra = mytext.ToCharArray();
foreach (char a in arra)
{
   if (a == 'h')
   {
      richtig = true;
    }
}
Naworia is offline  
Old 11/05/2012, 12:28   #3
 
elite*gold: 0
Join Date: May 2010
Posts: 793
Received Thanks: 268
Quote:
Originally Posted by master_oli View Post
Ich hätte da mal eine frage zu der ArrayList in C#

Und zwar ich möchte gerne in ihr String suchen jedoch wenn sie 1000 oder mehr inhalte hat dauert das sehr lange

Code:
int anzahl = arra.Count;
            for(int i = 0;i < anzahl;i++)
            {
                if (arra[i].ToString() == "h")
                {
                    richtig = true;
                }
                else
                {
                    richtig = false;
                }
            }
gibt es eine schneller methote als diese?
danke schon mal für die Hilfe
was für Objekte sind in deiner ArrayList denn drinne? Generell ist meiner meinung nach List<T> IMMER besser als ArrayList weil es ein generischer typ ist. ArrayList kommt noch aus den zeiten von .NET 1.0

naja wen du oft ein objekt anhand des names suchst ist HashSet<T> oder Dictionary<K,V> die beste Wahl, dafür dauert dann das hinzufügen von elmenten zu deiner Liste etwas länger.

Quote:
Originally Posted by Naworia View Post
I think you are making hangman or something like this.

It's no problem that your script is long or short. But I can show you example shorter:
Code:
char[] arra = new char[50];
bool richtig = false;
string mytext = "hellboy";
arra = mytext.ToCharArray();
foreach (char a in arra)
{
   if (a == 'h')
   {
      richtig = true;
    }
}
der code macht aber auch was ganz anderes.
nkkk is offline  
Old 11/05/2012, 16:12   #4
 
elite*gold: 35
Join Date: Jun 2012
Posts: 1,126
Received Thanks: 43
Also es sind Strings in meinem Arraylist die ständig sich weiter füllen soll
Wie kann ich eine Dictionary machen?
master_oli is offline  
Old 11/05/2012, 16:17   #5
 
Kraizy​'s Avatar
 
elite*gold: 0
The Black Market: 471/0/0
Join Date: Apr 2010
Posts: 9,696
Received Thanks: 1,811
Kraizy​ is offline  
Thanks
1 User
Old 11/05/2012, 16:42   #6
 
elite*gold: 0
Join Date: May 2010
Posts: 793
Received Thanks: 268
da ja der key genau der gleiche ist wie der wert ist wohl HashSet<T> die beste wahl. Allerdrings verstehe ich nicht ganz was du machen willst willst du nur überprüfen ob die liste den String bereits enthält?
nkkk is offline  
Old 11/06/2012, 19:51   #7

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
am besten ma erklären was du machen willst, dann können wir dir die richtige vorgehensweise sagen
x]vIrus[x is offline  
Reply


Similar Threads Similar Threads
Java - MinHeap als ArrayList
06/10/2012 - General Coding - 4 Replies
Meine Aufgabe (Studium zum Ingenieurinformatiker) für diese Woche lautet unter anderem: Hier mein Ansatz bisher: import java.util.*; public class MinHeap<T extends Comparable<T>> { private A - Pastebin.com Ich denke mal, ich zähle irgendwo ganz klar falsch... aber ich sehs nicht -.-
[Intermediate] Competing against Microsofts ArrayList
08/28/2008 - CO2 Programming - 3 Replies
Performance status: (Attempting to add 1,000,000 Elements) Flexible: 156ms List: 234ms Improvement Speed: 40-50% (Attempting to remove 1,000 Elements) Flexible: 16ms List: 7907ms



All times are GMT +1. The time now is 06:07.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.