By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,050 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,050 IT Pros & Developers. It's quick & easy.

foreach help

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.