string AllPDF = "";
int CountPDF = 0;
AllPDF = txtInput.Text;
string[] AllPDF2 = AllPDF.Split(';');
List<string> PDF = new List<string>();
PDF.AddRange(AllPDF2);
while (PDF.Count != CountPDF)
{
    File.Delete(AllPDF2[0 + CountPDF] + ".pdf");
	CountPDF++;
}

I believe, there are so many easier ways to do that

By Anonymous, 2018-03-27 12:15:10
const int ONLY_ONE_ITEM = 1;

if (myList.Count > ONLY_ONE_ITEM)
{
    DoSomething();
}
else
{
    DoSomethingElse();
}
By Anonymous, 2018-05-15 17:04:22
 if (!String.IsNullOrEmpty(Client.CLADDR1))
            {
                if (Client.CLADDR1 == "NULL")
                {
By Anonymous, 2017-06-29 12:33:24
private readonly FooType _foo = new FooType();

/// <summary>
/// Gets the controller of this component
/// </summary>
private FooType Foo
{
    get
    {
        return _foo;
    }
}
By Anonymous, 2018-07-25 13:55:26
/// <summary>
/// Returns true if any component of of Vector3 v is negative
/// </summary>
public static bool Ext_IsNegative(this Vector3 v)
{
    return v.x < 0f && v.y < 0f && v.z < 0f;
}

Either the description is wrong or the method in itself

By SwagridOfficial, 2017-12-13 13:00:34
namespace network
{
    class ip
    {
        uint _IP;
        public ushort this[int i]
        {
            get
            {
                switch(i)
                {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                        return (ushort)(_IP>>(i*8));
                    default:
                    throw new IndexOutOfRangeException();
                }
            }
            set
            {
                switch(i)
                {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                        _IP=(((uint)value)<<i*8);
                        break;
                    default:
                    throw new IndexOutOfRangeException();
                }
            }
        }
    }
}

I have no idea what this does

By Anonymous, 2022-04-26 16:20:05
// IsFooBar being a boolean, we check if it's different from true and from false
if (x.IsFooBar != true && x.IsFooBar != false)
{
    return "error";
}

x.IsFooBar is juste a regular bool

By A senior developer, 2018-05-14 14:46:14
public class MetricsChecker
{
    protected const string AwaitingRecognitionCountMetricName = "AwaitingRecognitionCount";
    protected const string AwaitingExportCountMetricName = "AwaitingExportCount";
    protected const string NotYetDownloadedEventCountMetricName = "NotYetDownloadedEventCount";
    
    ...
    
    public virtual void PublishNotYetDownloadedEventCounts()
    {
        this.logger.Trace($"Starting to gather and publish {NotYetDownloadedEventCountMetricName}(s).");
        ...
    }
    
    ...
}
By Senior developer with 30 rear experience, 2019-12-13 16:22:28
public static class time
{
    public const int minutes_per_hour = 60;
    public const int seconds_per_minute = 60;
    public const int hours_per_day = 24;
    public const int minutes_per_day = minutes_per_hour * hours_per_day;
    public const int seconds_per_day = seconds_per_minute * minutes_per_day;
    public const int days_per_year = 365;
}
By Anonymous, 2018-10-15 17:15:52
var list = new List<string>() { // Assume some items in the list };

for (var i = 0; i < list.Count; i++)
{
    var item = list[i];
    list.Remove(item);
    
    i--;
}

Simple alternative to List.Clear()

By Taylor, 2017-12-13 07:07:56
StartCoroutine(Patrol());

public IEnumerator Patrol() {
    while(true) {
        dt.Walk();
        yield return new WaitForSeconds(reactionTime);
    }
}
By Mario, 2021-11-19 07:18:22
        public static bool ValidateEmailAddress(string emailAddress)
        {
            string pattern = "^((?>[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+\x20*|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\"\x20*)*(?<angle><))?((?!\\.)(?>\\.?[a-zA-Z\\d!#$%&'*+\\-/=?^_`{|}~]+)+|\"((?=[\x01-\x7f])[^\"\\]|\\[\x01-\x7f])*\")@(((?!-)[a-zA-Z\\d\\-]+(?<!-)\\.)+[a-zA-Z]{2,}|\\[(((?(?<!\\[)\\.)(25[0-5]|2[0-4]\\d|[01]?\\d?\\d)){4}|[a-zA-Z\\d\\-]*[a-zA-Z\\d]:((?=[\x01-\x7f])[^\\\\[\\]]|\\[\x01-\x7f])+)\\])(?(angle)>)$";

            if (!String.IsNullOrEmpty(emailAddress) && !(Regex.Match(emailAddress.Trim(), pattern, RegexOptions.IgnoreCase)).Success)
            {
                return false;
            }
            return true;
        }
By Anonymous, 2019-07-17 23:47:20
class ExampleClass {
    public void DoSomething()
    {
       if (this != null) {
           //omitted
       }
    }
    
    public void DoSomething2()
    {
       if (this != null) {
           //omitted
       }
    }
    
}

Explanation: This can't be null in C# virtual instance methods - I was so confused by the widespread use of this check that I asked this question at SO: https://stackoverflow.com/questions/31747718/can-this-be-null-in-c-sharp-virtual-methods-what-happens-with-the-rest-of-ins

By Michail Michailidis, 2017-12-13 14:54:58
#411 C# +9
if (date.Training != null)
            {
                var training = date.Training;
                var status = new TrainingStatus();
                var refresher = new Training();

                if (training.Trainings != null)
                    refresher = training.Trainings;

                bool hasTakenRefresher = false;
                status.Value = date.Date.AddDays(
                    TrainingHelper.CalculateValidityDays(training.Validity ?? 0, training.ValidityType ?? 0));

                status.Name = training.TrainingName;
                status.ID = training.TrainingID;
                status.Category = training.CategoryTraining != null ? training.CategoryTraining.Name : "Other";
                status.IsTrained = _validityUtilsService.IsValid(training, date.Date);

                if (status.IsTrained)
                {
                    status.IsExpiring = _validityUtilsService.IsExpiring(training, date.Date,
                                            TrainingHelper.CalculateValidityDays(
                                                training.ExpirationWarningValidity ?? 0,
                                                training.ExpirationWarningValidityType ?? 0));
                }

                if (refresher.ID != 0)
                {
                    hasTakenRefresher = employee.Dates
                        .Count(x => x.Training != null
                            && x.TrainingID == refresher.ID) > 1;

                    if (hasTakenRefresher && (status.IsExpiring || !status.IsTrained))
                    {
                        status.IsExpiring = false;
                        var trainingWithNewValidity = new Training();

                        status.Value = date.Date.AddDays(
                            TrainingHelper.CalculateValidityDays(training.ValidityRefresher ?? 0,
                                training.ValidityRefresherType ?? 0));

                        trainingWithNewValidity.Validity = training.ValidityRefresher;
                        trainingWithNewValidity.ValidityType = training.ValidityRefresherType;
                        status.IsTrained = _validityUtilsService.IsValid(trainingWithNewValidity, date.Date);

                        if (status.IsTrained)
                        {
                            status.IsExpiring = _validityUtilsService.IsExpiring(trainingWithNewValidity, date.Date,
                                TrainingHelper.CalculateValidityDays(
                                    refresher.ExpirationWarningValidity ?? 0,
                                    refresher.ExpirationWarningValidityType ?? 0));
                        }
                    }
                }

                if (status.IsTrained && !status.IsExpiring)
                    status.Status = TrainingStatuses.Trained;
                else if (status.IsTrained && status.IsExpiring)
                    status.Status = TrainingStatuses.Expiring;
                else if (!status.IsTrained && !status.IsExpiring)
                    status.Status = TrainingStatuses.Expired;

                status.EmpID = employee.ID;

                return status;
            }

test

By NN, 2019-10-29 12:59:14
        protected override void OnStartup(StartupEventArgs e)
        {
            Current.DispatcherUnhandledException += ApplicationUnhandledException;

            base.OnStartup(e);

#if (DEBUG)
            RunInDebugMode(e.Args);
#else
            RunInReleaseMode(e.Args);
#endif
        }

#endregion

        private static void RunInReleaseMode(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;

            try
            {
                SplashScreen screen = new SplashScreen(@"Images\splashscreen.png");
                screen.Show(true, true);

                RunInDebugMode(args);
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }

        private static void RunInDebugMode(string[] args)
        {
            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();
        }
By Anonymous, 2019-07-09 09:44:00