public event EventHandler<Cles_graph_doivent_etre_redessines> les_graph_doivent_etre_redessines;
public void remove_event()
{
if (this.les_graph_doivent_etre_redessines != null)
{
foreach (EventHandler<Cles_graph_doivent_etre_redessines> F_les_graph_doivent_etre_redessines in this.les_graph_doivent_etre_redessines.GetInvocationList())
{
this.les_graph_doivent_etre_redessines -= F_les_graph_doivent_etre_redessines;
}
}
}
foreach (Byte bajt in data ) {
BufferIndex = i++;
if (!char.IsControl((char)bajt))
MyCharacter = Convert.ToChar(bajt).ToString();//Encoding.ASCII.GetString(new[]{bajt});
else
MyCharacter = " ";
if (BufferIndex == 200)
{
int a = BufferIndex;
}
if (BufferIndex < 200)
{
sw.WriteLine("PrintBuffer1[" + BufferIndex + "] :=\t" + bajt + "\t; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + "\t" + MyCharacter );
}
if (BufferIndex >= 200 && BufferIndex < 400)
{
BufferIndex = BufferIndex - 200;
sw.WriteLine("PrintBuffer2[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 400 && BufferIndex < 600)
{
BufferIndex = BufferIndex - 400;
sw.WriteLine("PrintBuffer3[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 600 && BufferIndex < 800)
{
BufferIndex = BufferIndex - 600;
sw.WriteLine("PrintBuffer4[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 800 && BufferIndex < 1000)
{
BufferIndex = BufferIndex - 800;
sw.WriteLine("PrintBuffer5[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 1000 && BufferIndex < 1200)
{
BufferIndex = BufferIndex - 1000;
sw.WriteLine("PrintBuffer6[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 1200 && BufferIndex < 1400)
{
BufferIndex = BufferIndex - 1200;
sw.WriteLine("PrintBuffer7[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 1400 && BufferIndex < 1600)
{
BufferIndex = BufferIndex - 1400;
sw.WriteLine("PrintBuffer8[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 1600 && BufferIndex < 1800)
{
BufferIndex = BufferIndex - 1600;
sw.WriteLine("PrintBuffer9[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 1800 && BufferIndex < 2000)
{
BufferIndex = BufferIndex - 1800;
sw.WriteLine("PrintBuffer10[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 2000 && BufferIndex < 2200)
{
BufferIndex = BufferIndex - 2000;
sw.WriteLine("PrintBuffer11[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
if (BufferIndex >= 2200 && BufferIndex < 2400)
{
BufferIndex = BufferIndex - 2200;
sw.WriteLine("PrintBuffer12[" + BufferIndex + "] :=" + bajt + "; // " + String.Format(@"0x{0:x2}", (ushort)bajt) + " " + MyCharacter);
}
}
don't repeat yourself.. whyy we don't have PrintBufeer[i] ?
protected Int32 Sum(int one, int two)
{
int result;
int tmp;
tmp = one + two;
result = tmp;
return result;
}
Jesus.
private void reset_kolejnosc()
{
this.kolejnosc_s[0] = 1;
this.kolejnosc_s[1] = 2;
this.kolejnosc_s[2] = 3;
this.kolejnosc_s[3] = 4;
this.kolejnosc_s[4] = 5;
this.kolejnosc_s[5] = 6;
this.kolejnosc_s[6] = 7;
this.kolejnosc_s[7] = 8;
this.kolejnosc_s[8] = 9;
this.kolejnosc_s[9] = 10;
}
//this is a commit!!
trans.Commit();
It doesn't look like it was there because of some changes - someone simply wanted to be double sure he will see the commit there, I guess..
if (!String.IsNullOrEmpty(Client.CLADDR1))
{
if (Client.CLADDR1 == "NULL")
{
bool b = connection.isConnected() == true ? true : false;
My first internship presented me with this.
string month = DateTime.Today.Month.ToString();
if (DateTime.Today.Month < 10)
{
month = "0" + month;
}
string day = DateTime.Today.Day.ToString();
if (DateTime.Today.Day < 10)
{
day = "0" + day;
}
string dateCorrect = String.Format("{0}.{1}.{2}", DateTime.Today.Year, month, day);
string dateDue = "";
if (transferFields.DueDate.SelectedDate.HasValue)
{
var dateDuearr = transferFields.DueDate.Value.Split(' ')[0].Split('.');
dateDue = dateDuearr[2] + '.' + dateDuearr[1] + '.' + dateDuearr[0];
}
else {
dateDue = dateCorrect;
}
Real developers don't use built in parsing and formatting methods.
public static class DecimalHelpers
{
/// <summary>
/// Format a decimal XX.XX to XX,XX%.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string FormatToStringPercentageValue(this decimal value)
{
return value.ToString().Replace(".", ",").FormatToPercentageValue();
}
}
public static class StringHelpers
{
/// <summary>
/// Add % at the end of the string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string FormatToPercentageValue(this string value)
{
return string.Concat(value, "%");
}
}
public static bool HasValues<T>(this ICollection<T> collection)
{
if (collection == null)
{
return false;
}
if (collection.Count == 0)
{
return false;
}
return true;
}
protected void EnableEditButtons(bool Value)
{
if (Value == false)
{
buttonAdd.Disabled = true;
buttonDelete.Disabled = true;
}
else
{
buttonAdd.Disabled = false;
buttonDelete.Disabled = false;
}
}
// ...
if (IsEditable(ID))
EnableEditButtons(true);
else
EnableEditButtons(false);
I found this old code in an app I was updating for a client a number of years back. It was so good I documented it on my own blog.
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
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
string str = Console.ReadLine();
string len = 0;
for(int i = 0; i < str.Length; i++)
{
len++;
}
Let's get string length :| Dummy