Skip to main content
tidy up to expose core logic
Source Link

I would think this will do it:

var matches = profiles.Where(p => p.Name.StartsWith(newProf.Name));

string candidate = newProf.Name;

if (matchesprofiles.Any(p => p.Name == candidatenewProf.Name))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    string candidate = String.Format(template, counter);

    while (matchesprofiles.Any(p => p.Name == candidate))
    {
        counter++;
        candidate = String.Format(template, counter);
    }

    newProf.Name = candidate;
}

I would think this will do it:

var matches = profiles.Where(p => p.Name.StartsWith(newProf.Name));

string candidate = newProf.Name;

if (matches.Any(p => p.Name == candidate))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    candidate = String.Format(template, counter);

    while(matches.Any(p => p.Name == candidate) {
        counter++;
        candidate = String.Format(template, counter);
    }

    newProf.Name = candidate;
}

I would think this will do it:

if (profiles.Any(p => p.Name == newProf.Name))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    string candidate = String.Format(template, counter);

    while (profiles.Any(p => p.Name == candidate))
    {
        counter++;
        candidate = String.Format(template, counter);
    }

    newProf.Name = candidate;
}
added 14 characters in body
Source Link

I would think this will do it:

var matches = profiles.Where(p => p.Name.StartsWith(newProf.Name));

string candidate = newProf.Name;

if (matches.Any(p => p.Name == candidate))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    candidate = String.Format(template, counter); 

    while(matches.Any(p => p.Name == candidate) {
        counter++;
        candidate = String.Format(template, counter);
    }
}

    newProf.Name = candidate;
}

I would think this will do it:

var matches = profiles.Where(p => p.Name.StartsWith(newProf.Name));

string candidate = newProf.Name;

if (matches.Any(p => p.Name == candidate))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    candidate = String.Format(template, counter);
    while(matches.Any(p => p.Name == candidate) {
        counter++;
        candidate = String.Format(template, counter);
    }
}

newProf.Name = candidate;

I would think this will do it:

var matches = profiles.Where(p => p.Name.StartsWith(newProf.Name));

string candidate = newProf.Name;

if (matches.Any(p => p.Name == candidate))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    candidate = String.Format(template, counter); 

    while(matches.Any(p => p.Name == candidate) {
        counter++;
        candidate = String.Format(template, counter);
    }

    newProf.Name = candidate;
}
Source Link

I would think this will do it:

var matches = profiles.Where(p => p.Name.StartsWith(newProf.Name));

string candidate = newProf.Name;

if (matches.Any(p => p.Name == candidate))
{
    string template = newProf.Name + " ({0})";
    int counter = 1;
    candidate = String.Format(template, counter);
    while(matches.Any(p => p.Name == candidate) {
        counter++;
        candidate = String.Format(template, counter);
    }
}

newProf.Name = candidate;