Skip to main content
replaced http://meta.codereview.stackexchange.com/ with https://codereview.meta.stackexchange.com/
Source Link
static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use arrays to store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a buga bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success
static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use arrays to store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success
static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use arrays to store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success
typos fixed.
Source Link
rolfl
  • 98.2k
  • 17
  • 220
  • 419
static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use array soarrays to store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success
static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use array so store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success
static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use arrays to store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success
Source Link
svick
  • 24.5k
  • 4
  • 53
  • 89

static void Main(string[] args)

If you're not going to use args, you can omit them:

static void Main()

const string conStrName = "aspnetdbConnectionString";
SqlConnectionStringBuilder cns = new SqlConnectionStringBuilder(conString);

Try not to abbreviate variable names, it makes your code harder to understand.

Also, consider using var, especially if the type of the variable is clear from the right side of the assignment.


string SQLServerName = cns.DataSource;

Local variables should start with a lowercase letter: sqlServerName.


List<string[]> userList = new List<string[]>
{
    new[] { "admin", "adminPa$$word1234", "[email protected]", "admin poweruser export", "Jan Admin", "111 222 333" },
    new[] { "admin2", "admin2Pa$$word1234", "[email protected]", "admin poweruser", "Petr Admin", "222 333 444" },
    new[] { "admin3", "admin3Pa$$word1234", "[email protected]", "admin", "Lenka Admin", "333 444 555" },
};

foreach (var info in userList)
{
    string name = info[0];
    string password = info[1];
    string email = info[2];

You shouldn't use array so store this kind of information, it's logically not an array.

You can use an anonymous type instead:

new { name = "admin", password = "adminPa$$word1234", email = "[email protected]", roleNames = new[] { "admin", "poweruser", "export" }, fullName = "Jan Admin", phone = "111 222 333" }

Note that this means it's much harder to confuse which array index contains which value and you can (and should) use types other than string.

(The incorrect indentation in the original code is due to a bug.)


MembershipCreateStatus status = new MembershipCreateStatus();
memProv.CreateUser(name, password, email,
    "none", // password question
    "none", // password answer
    true,   // isApproved
    null,   //
    out status);
  • You don't need to initialize out variables. (And newing up an enum doesn't make much sense either.)

  • Instead of comments, you should use named arguments, that way, the compiler verifies the names for you (comments can be wrong, code can't).

Put together:

MembershipCreateStatus status;
memProv.CreateUser(name, password, email,
    passwordQuestion: "none",
    passwordAnswer: "none",
    isApproved: true,
    providerUserKey: null,
    status: out status);

status.Equals(MembershipCreateStatus.Success)

You can compare enums using ==:

status == MembershipCreateStatus.Success