Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# equivalent of nextElement() from Java

Tags:

java

c#

.net

What is the equivalent of nextElement() from Java?

I have the following code:

IEnumerable<String> e = (IEnumerable<String>)request
                                        .Params;

while (e.Count() > 1)
{
 // 
 //String name = e.nextElement();
String name = e. // what method?
}
like image 684
el.severo Avatar asked Dec 20 '22 04:12

el.severo


1 Answers

You should be using the foreach loop:

foreach (string name in request.Params)
{
    // Do something for each name
}

If you really want to use the raw enumerable, then you have call its GetEnumerator() method:

using (IEnumerator<string> enumerator = request.Params.GetEnumerator())
{
    while (enumerator.MoveNext())
    {
        string name = enumerator.Current;

        // Do something for each name
    }
}

However, the foreach syntax is much clearer. Use that.

like image 148
dlev Avatar answered Jan 01 '23 15:01

dlev