I am trying to reference some random users generated in one class I made in another class where I am going to use them.
public static void RandUserName(string domain, string FullName, string Email)
{
string firstName = "";
string lastName = "";
string phone = "";
RandomUserName(domain, firstName, lastName, Email, phone);
FullName = String.Format("{0} {1}.com", firstName, lastName);
}
Public static void RandName(string FirstName, string LastName)
{
string[] maleNames = new string [1000]{"aaron", "abdul", "abe", "abel"};
string[] femaleNames = new string [1000] {"abby", "abigail", "ada"};
string[] lastNames = new string[1000] {"abbott", "acevedo", "acosta"};
Random rand = new Random(DateTime.Now.Second);
if (rand.Next(1, 2) == 1)
{
FirstName = maleNames[rand.Next(0, maleNames.Length-1)];
}
else
{
FirstName = femaleNames[rand.Next(0, femaleNames.Length-1)];
}
}
public static string RandomUserName(string Domain, string FirstName, string LastName, string Email, string phone)
{
RandName(FirstName, LastName);
if (string.IsNullOrEmpty(Domain))
{
Domain = String.Format("{0}{1}.com", FirstName, LastName);
}
Email = "Tester" + LastName + "@" + Domain;
phone = "850-555-1234";
return FirstName;
}
Here is where I want to reference these names to in VB.net. I am trying to translate this to c#, these come from a request I am making:
RandInfo.RandomUserName(Domain, .PrimaryContact.FirstName, .PrimaryContact.LastName, .PrimaryContact.Email, .PrimaryContact.Phone)
RandInfo.RandomUserName(Domain, .BillingContact.FirstName, .BillingContact.LastName, .BillingContact.Email, .BillingContact.Phone)
RandInfo.RandomUserName(Domain, .TechContact.FirstName, .TechContact.LastName, .TechContact.Email, .TechContact.Phone)
RandInfo.RandomUserName(Domain, .EmergencyContact.FirstName, .EmergencyContact.LastName, .EmergencyContact.Email, .EmergencyContact.Phone)
Sorry if all this is confusing! Please ask any questions you have to understand and help!
First of all: i think you may have misunderstood the concept of functions/method. The
voidin your ‘RandUserName’ function is where you would declare the return type.A small example:
A call like this:
would return “John Doe”. An (ugly) alternative way would be to declare the parameters in your methods as out parameters, but i would try to avoid that.
What you want to achieve can be done in various way, i would start with designing a
Userclass with properties forFirstName,LastName,Phoneand so on.Then you could create a function that generates instances of this class, its properties filled with random values.
But i guess you would have to put some effort into it for yourself.