How do I write this java code in C#
-
// Search Operations // I am trying to search a textbox entry in a linkedlist queue implementation such that if the entry is there in the recorded queue then I get a message that it is actually there. Thanks --------------------------------------------------------------------- public int indexOf(Object o) { int index = 0; if (o==null) { for (Entry e = header.next; e != header; e = e.next) { if (e.element==null) return index; index++; } } else { for (Entry e = header.next; e != header; e = e.next) { if (o.equals(e.element)) return index; index++; } } return -1; }
-
// Search Operations // I am trying to search a textbox entry in a linkedlist queue implementation such that if the entry is there in the recorded queue then I get a message that it is actually there. Thanks --------------------------------------------------------------------- public int indexOf(Object o) { int index = 0; if (o==null) { for (Entry e = header.next; e != header; e = e.next) { if (e.element==null) return index; index++; } } else { for (Entry e = header.next; e != header; e = e.next) { if (o.equals(e.element)) return index; index++; } } return -1; }
Why don't you implement the in built Binary search method, if you use ArrayList class.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
modified on Wednesday, September 10, 2008 4:48 AM
-
Why don't you implement the in built Binary search method, if you use ArrayList class.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
modified on Wednesday, September 10, 2008 4:48 AM
-
//Create a object System.Collections.ArrayList oArrayList = new System.Collections.ArrayList(); // Add all your entries in ArrayList Object in form load event or the event which suited your problem oArrayList.add(/* Your entry*/); //then search for a value whether it exists or not bool isexist=oArrayList.contains("Your search value");//method returns true if your search value exist.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
-
//Create a object System.Collections.ArrayList oArrayList = new System.Collections.ArrayList(); // Add all your entries in ArrayList Object in form load event or the event which suited your problem oArrayList.add(/* Your entry*/); //then search for a value whether it exists or not bool isexist=oArrayList.contains("Your search value");//method returns true if your search value exist.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
Mogaambo wrote:
System.Collections.ArrayList
Use a strongly typed generic
List<T>
instead of arraylist.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Mogaambo wrote:
System.Collections.ArrayList
Use a strongly typed generic
List<T>
instead of arraylist.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Have got the linkedlist running with data stored in a queue already but not sure of how to search through the queue whether the textbox entry exists in the queue or not.
Angelinna wrote:
data stored in a queue
Your question is not clear. Are you using a generic
Queue<T>
? if yes, it has a Contains()[^] method which can be used.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Why don't you implement the in built Binary search method, if you use ArrayList class.
“You will never be a leader unless you first learn to follow and be led.” –Tiorio "Coming together is a beginning, staying together is progress, and working together is success." Henry Ford
modified on Wednesday, September 10, 2008 4:48 AM
-
Angelinna wrote:
data stored in a queue
Your question is not clear. Are you using a generic
Queue<T>
? if yes, it has a Contains()[^] method which can be used.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions