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
const int ONLY_ONE_ITEM = 1;
if (myList.Count > ONLY_ONE_ITEM)
{
DoSomething();
}
else
{
DoSomethingElse();
}
if (!String.IsNullOrEmpty(Client.CLADDR1))
{
if (Client.CLADDR1 == "NULL")
{
// 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
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
private readonly FooType _foo = new FooType();
/// <summary>
/// Gets the controller of this component
/// </summary>
private FooType Foo
{
get
{
return _foo;
}
}
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).");
...
}
...
}
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;
}
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()
/// <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
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();
}
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
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
StartCoroutine(Patrol());
public IEnumerator Patrol() {
while(true) {
dt.Walk();
yield return new WaitForSeconds(reactionTime);
}
}
/// <summary>
/// Builds the suffixs for the request sequence number
/// </summary>
/// <param name="i"></param>
/// <returns></returns>
public static string GetSequenceNumber(int i)
{
string strCount = string.Empty;
string increase = string.Empty;
int count;
strCount = i.ToString();
count = strCount.Length;
//Add 0 infront of the index to make a 4 digit number
if (count < 5)
{
for (int j = 0; j < (4 - count); j++)
{
increase = increase + "0";
}
strCount = increase + strCount;
}
return strCount;
}