473,513 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

foreach help

I tried to translate VB code for FOREACH and got this result:

public static string GetUnauthorizedUsersCount() {
MembershipUser objUser;
MembershipUserCollection objUserCollection = Membership.GetAllUsers();
MembershipUserCollection objUsers = new MembershipUserCollection();

foreach (objUser in objUserCollection)
{
if ((objUser.IsApproved == false))
{
objUsers.Add(objUser);
}
}
if ((objUsers.Count 0))
{
return objUsers.Count.ToString();
}
else {
return "0";
}
}

Compiler complains about 'in' in foreach (objUser in objUserCollection)
'Type and identifier are both required in a foreach statement '

If I put MembershipUser as a type I get another error:
'A local variable named 'objUser' cannot be declared in this scope because
it would give a different meaning to 'objUser', which is already used in a
'parent or current' scope to denote something else

How should I rewrite this FOREACH?

Thank you

Esha
Oct 2 '06 #1
2 4082
"esha" <es**@newsgroups.comwrote in message
news:OD*************@TK2MSFTNGP04.phx.gbl...
>I tried to translate VB code for FOREACH and got this result:

public static string GetUnauthorizedUsersCount() {
MembershipUser objUser;
^^^ delete this line
MembershipUserCollection objUserCollection = Membership.GetAllUsers();
MembershipUserCollection objUsers = new MembershipUserCollection();

foreach (objUser in objUserCollection)
^^^ replace this line with:
foreach (MembershipUser objUser in objUserCollection)
{
if ((objUser.IsApproved == false))
{
objUsers.Add(objUser);
}
}
if ((objUsers.Count 0))
{
return objUsers.Count.ToString();
}
else {
return "0";
}
}

Compiler complains about 'in' in foreach (objUser in
objUserCollection)
'Type and identifier are both required in a foreach statement '

If I put MembershipUser as a type I get another error:
'A local variable named 'objUser' cannot be declared in this scope because
it would give a different meaning to 'objUser', which is already used in a
'parent or current' scope to denote something else

How should I rewrite this FOREACH?
See inline above.

-cd
Oct 2 '06 #2
Thanks a lot

Esha

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:eu**************@TK2MSFTNGP05.phx.gbl...
"esha" <es**@newsgroups.comwrote in message
news:OD*************@TK2MSFTNGP04.phx.gbl...
>>I tried to translate VB code for FOREACH and got this result:

public static string GetUnauthorizedUsersCount() {
MembershipUser objUser;

^^^ delete this line
> MembershipUserCollection objUserCollection = Membership.GetAllUsers();
MembershipUserCollection objUsers = new MembershipUserCollection();

foreach (objUser in objUserCollection)

^^^ replace this line with:
foreach (MembershipUser objUser in objUserCollection)
> {
if ((objUser.IsApproved == false))
{
objUsers.Add(objUser);
}
}
if ((objUsers.Count 0))
{
return objUsers.Count.ToString();
}
else {
return "0";
}
}

Compiler complains about 'in' in foreach (objUser in
objUserCollection)
'Type and identifier are both required in a foreach statement '

If I put MembershipUser as a type I get another error:
'A local variable named 'objUser' cannot be declared in this scope
because it would give a different meaning to 'objUser', which is already
used in a 'parent or current' scope to denote something else

How should I rewrite this FOREACH?

See inline above.

-cd


Oct 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4284
by: Randell D. | last post by:
Folks, Ever since reading an interesting article in Linux Format on PHP whereby suggested code writing was made that could enhance performance on a server, I've started testing various bits of...
32
4094
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
3
7094
by: Hans | last post by:
I implemented the IEnumerator interface in some classes to enable the use of the foreach statement. As you probalbly know, the interface asks for the implementation of object IEnumerator.Curren...
104
7047
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
14
1786
by: Josh Ferguson | last post by:
I don't believe a syntax driven equivalent exists for this, but I just thought it would be neat if you could use foreach to do something like this: foreach (Object x in collection1, collection2)...
13
14438
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in...
13
5186
by: matt | last post by:
I have this bit of code, that isn't valid, and I need some help getting it to work... Currently, I get an error because I am calling the next() function within a foreach loop. I am opening a flat...
9
5590
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
1
3344
by: greyseal96 | last post by:
Hi, I am a pretty new programmer, so I apologize in andvance if this is a dumb question... In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
4
6279
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.