Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir

In my c sharp programming
in following code

string[] readText = File.ReadAllLines(path);

readText contains array of 10000 rows

now i created two string array variable

C#
string[] badEmail;
     string[] goodemail;



in below code i validEmail(readText[i]) method check emails are valid or not.

C#
for (int i = 1; i < readText.Length; i++)
                {
                    if (validEmail(readText[i]))  // check valid
                    {
                        badEmail[] = readText[i];
                        m++;
                    }
                }



if email is bad, i wants it in badEmail[]
and if
email is good i want it in goodEnail[]

In advance i dont know how many bad emails so how i can do?
please give me solution
Thanks.
Posted

Use List<t>[^] instead of an array so
C#
List<string> badEmail = new List<string>();
List<string> goodEmail = new List<string>();
for (int i = 1; i < readText.Length; i++)
{
    if (validEmail(readText[i]))  // check valid
    {
        badEmail.Add(readText[i]); // Are you sure this should be a bad email?
        m++;                       // the method name validEmail, would seem
    }                              // indicate that it's a "good" email.
}
 
Share this answer
 
v2
Comments
udusat13 24-Aug-11 8:34am    
Thanks sir.
its working
Uday P.Singh 24-Aug-11 8:36am    
good one my 5!
Simon Bang Terkildsen 24-Aug-11 9:03am    
Thank you
Use linq
Sorry this is in VB, you can do it in C#.
SQL
Dim goodemails() As String = (From email As String In readText Where validEmail(email) Select email).toArray
Dim bademails() As String = (From email As String In readText Where Not validEmail(email) Select email).toArray
 
Share this answer
 
Comments
Simon Bang Terkildsen 24-Aug-11 8:27am    
The OP seem to be at a very basic level, so using Linq wont help him, unless he doesn't care about learning and just copy-paste the code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900