- 1
- 2
- 3
- 4
- 5
- 6
- 7
void makeGetSet(ref int delegate() get, ref void delegate(int) set)
{
int _data = 0;
get = {return _data;};
set = (int Data){_data = Data;};
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+117
void makeGetSet(ref int delegate() get, ref void delegate(int) set)
{
int _data = 0;
get = {return _data;};
set = (int Data){_data = Data;};
}
+115
<%=Convert.ToDateTime(item.CreatedOnDate).ToString("D", new System.Globalization.CultureInfo(System.Globalization.CultureInfo.CurrentCulture.ToString()))%>
Кусок кода, который отображает некую дату
+111
try
{
Int16 y = 0, m = 0, d = 0, hh = 0, mm = 0, ss = 0, ms = 0, zn = 0;
if (Value.IndexOf("T") > 0)
{
Int16.TryParse(Value.Substring(0, 4), out y);
Int16.TryParse(Value.Substring(4, 2), out m);
Int16.TryParse(Value.Substring(6, 2), out d);
Int16.TryParse(Value.Substring(9, 2), out hh);
Int16.TryParse(Value.Substring(11, 2), out mm);
Int16.TryParse(Value.Substring(13, 2), out ss);
Int16.TryParse(Value.Substring(16, 2), out ms);
Int16.TryParse(Value.Substring(18, 3), out zn);
dt = new DateTime(y, m, d, hh, mm, ss, ms, DateTimeKind.Utc);
}
if (Value.IndexOf("T") == 0)
{
Int16.TryParse(Value.Substring(0, 2), out hh);
Int16.TryParse(Value.Substring(2, 2), out mm);
Int16.TryParse(Value.Substring(4, 2), out ss);
Int16.TryParse(Value.Substring(7, 2), out ms);
dt = dt.AddHours(hh).AddMinutes(mm).AddSeconds(ss).AddMilliseconds(ms);
}
dt.AddHours(-zn);
catch (Exception ex)
{
Console.Write(this.Value + "\r\n" + ex.ToString());
}
return dt;
Разбор модифицированного iso 8601 формата даты и времени (без "-").
не учитавается наличие/отсуствие даты или времени, длинная тайм зона, то что если нет T то это не время а дата. Естественно все обернуто в try/catch что бы никто не догадался.
Так сказать особой утонченности придает строка dt.AddHours(-zn);
(сколько уйдет у кого секунд что бы понять что с ней не так?)
+106
proxy1.GetMeasurements(
new AccountingMeasurementType(255, "Тип документа")))
.ToList()
.FirstOrDefault(item =>
item.Name.Equals("Спецификация")
),
SpecificationDS.DateFrom as DateTime?,
SpecificationDS.DateTo as DateTime?)
);
Мало того что в коде прошита сразу куча строк, так еще и числовая константа %)
+122
int sum = 0;
sum += int.Parse( numericUpDown1.Value.ToString());
sum += int.Parse( numericUpDown2.Value.ToString() );
sum += int.Parse( numericUpDown3.Value.ToString() );
sum += int.Parse( numericUpDown4.Value.ToString() );
sum += int.Parse( numericUpDown5.Value.ToString() );
+112
public static string ConvertBase64ToString(string b64)
{
string Value = b64;
if (Value != null && Value.Length > 0)
{
System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
System.Text.Decoder decoder = encoder.GetDecoder();
byte[] bytes = Convert.FromBase64String(Value);
int charCount = decoder.GetCharCount(bytes, 0, bytes.Length);
char[] chars = new char[charCount];
decoder.GetChars(bytes, 0, bytes.Length, chars, 0);
string results = new String(chars);
return results;
}
return string.Empty;
}
не говоря уже про локальную переменную Value, весь блок заменяется на
return System.Text.ASCIIEncoding.ASCII.GetStrin g(Convert.FromBase64String(Value));
+112
static void Main(string[] args)
{
IPEndPoint myIP = null;
TcpListener server = null;
bool loop = true;
while (loop)
{
try
{
Random rnd = new Random(DateTime.Now.Millisecond);
new IPEndPoint(new IPAddress(new byte[] { 127, 0, 0, 1 }), rnd.Next(1000, 9999));
server = new TcpListener(myIP);
loop = false;
}
catch
{
loop = true;
}
}
//...
}
Подключаемся к серверу =)
+122
SqlCommand SomeCommand = new SqlCommand(SelectString, ConnectionString);
int result;
if(SomeCommand.ExecuteScalar() == null)
{
result = 0;
}
else
{
result = (int)SomeCommand.ExecuteScalar();
}
Why bad ?! The method execute twice ...
+121
private static readonly char SPECIFIER = "$"[0];
private static readonly char DELIMITER = ":"[0];
private static readonly char[] DELIMITER_ARRAY = new char[1] { DELIMITER };
В глубинах довольно большой CRM'ки
+121
lbxLibrary.Columns[2].ColumnWidth = lbxLibrary.Width - (2 + 15 + 4 + 15 + 4 + 15 + 4 + 16 + 2 + 2);
lbxSamples.Columns[2].ColumnWidth = lbxLibrary.Width - (2 + 15 + 4 + 15 + 4 + 15 + 4 + 16 + 2 + 2);
Американское спагетти.
Подобное содержится в методе InitializeComponent() более чем в 20-ти формах! Кто не помнит, InitializeComponent() формируется дизайнером автоматически, и крайне нежелательно вносить в него изменения. Везде разные объекты, и во многих местах отличны числа.