Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dynamically declared
Message
De
21/06/2013 13:12:12
 
 
À
21/06/2013 11:37:34
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01576814
Message ID:
01576825
Vues:
42
>>Hi,
>>
>>I have code like this:
>>
>>
            NetworkCredential cred = new NetworkCredential(smtpUser, smtpPassword);
>>            NetworkCredential cred1 = new NetworkCredential(justUser + "1" + justCredDomain, smtpPassword);
>>            NetworkCredential cred2 = new NetworkCredential(justUser + "2" + justCredDomain, smtpPassword);
>>            NetworkCredential cred3 = new NetworkCredential(justUser + "3" + justCredDomain, smtpPassword);
>>            NetworkCredential cred4 = new NetworkCredential(justUser + "4" + justCredDomain, smtpPassword);
>>
>>
>>How can I make this flexible where I can switch from 5 variables to 7 or whatever amount I want?
>>
>>I then need to use these in a loop where I send emails from different email address each pass through the loop. For example, first pass uses cred, second cred1, 3rd Cred2, etc and then when cred4 is reached the next loop would be cred again.
>>
>>I suppose some type of collection? Can anyone give me an example showing how to declare these and how to use them in later code? I am using C#.
>>
>>Thanks
>
>Try this:
>
>// Set CredentialCount to the number of credentials you want
>var credentials = new List<NetworkCredential>(CredentialCount + 1);
>credentials.Add(new NetworkCredential(smtpUser, smtpPassword));
>for(int index = 1; index <= CredentialCount; index++)
>	credentials.Add(new NetworkCredential(justUser + index.ToString() + justCredDomain, smtpPassword));
>
>foreach(var credential in credentials)
>{
>	// Send emails here.
>}
>
Thanks. To turn the logic around a bit. How would I refer to the nth credential in the list of credentials?

credentials[n]

?
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform