- 1
double pi = Math.Atan(1) * 4;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+129
double pi = Math.Atan(1) * 4;
Очередной велосипед.
+121
switch ((sender as Button).Name)
{
case "req_edit":
edit.source = requests;
break;
case "desc_edit":
edit.source = description;
break;
case "inst_edit":
edit.source = install;
break;
case "del_edit":
edit.source = uninstall;
break;
}
Открытие редактора по клику на кнопку возле поля ввода
+15
public class CheckBox : Control
{
private bool _isChecked;
public CheckBox(BizCheckBox source): base(source)
{
IsChecked = source.Checked;
}
public bool IsChecked
{
get
{
try
{
return Convert.ToBoolean(_isChecked);
}
catch
{
return false;
}
}
set { _isChecked = value; }
}
}
в место объявления автосвойства public bool IsChecked { get; set; }
+114
var panel = (StackPanel)((FrameworkElement)button.Parent).FindName("addContactPanel");
panel.Visibility = Visibility.Collapsed;
вместо простого addContactPanel.Visibility = Visibility.Collapsed;
+114
public IQueryable<Log> Select(Context context)
{
// Return list of entities
return (from l in context.Logs select l);
}
/// <summary>
/// Fetch page from Log table
/// </summary>
/// <param name="nStartRowIndex">Starting index of rows to fetch</param>
/// <param name="nMaxRows">Max number of rows</param>
/// <returns>IEnumerable of Log</returns>
public List<Log> SelectPage(int nStartRowIndex, int nMaxRows,
string strProperty, string strKeyword,
string strSort, string strSortDirection,
out int nTotalCount)
{
using (Context context = new Context())
{
var q = Select(context).Take (1000);
}
}
Коллега на работе наворотил...
+146
static void WriteToFile()
{
StreamWriter SW;
SW=File.CreateText("c:\\MyTextFile.txt");
SW.WriteLine("God is greatest of them all");
SW.WriteLine("This is second line");
SW.Close();
Console.WriteLine("File Created SucacessFully");
}
SucacessFully, что здесь непонятного!)
А строки 3 и 4 стоило написать в одну строчку сразу.
Источник: http://www.csharphelp.com/2005/12/simple-text-file-operations-in-c/
+131
DateTime dt = DateTime.Parse(DateTime.Now.ToString("dd.MM.yyyy"));
Вот такие гении встречаются в нашей местности....
+116
namespace Containers
{
public class TBinaryWaitingQueue<TItem> where TItem : struct
{
private readonly TBinaryQueue<TItem> _queue;
TBinaryWaitingQueue(int amountOfitem)
{
_queue = new TBinaryQueue<TItem>(amountOfitem);
}
public void Enqueue(TItem[] items)
{
throw new NotImplementedException();
}
public void Enqueue(TItem[] items, int beginItem, int amountOfItem)
{
throw new NotImplementedException();
}
public void Dequeue(TItem[] items, int beginItem, int amountOfItem)
{
throw new NotImplementedException();
}
public TItem[] Dequeue(int amountOfItem)
{
throw new NotImplementedException();
}
}
}
Досталось в наследство от предков. Этому коду уже года 4.
+118
public class TWriteableForEach
{
public delegate void TForEachDelegate<TItem>(TItem item);
public static void Exec<TItem>(IList<TItem> itemsCollection, TForEachDelegate<TItem> forEachDelegate)
{
for (int i = 0; i < itemsCollection.Count(); ++i)
forEachDelegate(itemsCollection[i]);
}
} ;
Велосипед с квадратными колёсами?
+116
public class TObjects
{
public delegate T DeferredConstruction<out T>();
public static void Dispose<T>(ref T objectForDispose)
{
var typeOfObjectForDispose = typeof(T);
if (!typeOfObjectForDispose.IsClass)
DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
else
if (!Equals(objectForDispose, null))
DisposeIfIDisposable(ref objectForDispose, typeOfObjectForDispose);
objectForDispose = default(T);
//objectForDispose = (T)(object)(null);
}
public static void Create<T>(ref T objectForCreate, DeferredConstruction<T> newObject)
{
Dispose(ref objectForCreate);
objectForCreate = newObject();
}
private static void DisposeIfIDisposable<T>(ref T objectForDispose, Type typeOfObjectForDispose)
{
bool canDisposable = (objectForDispose as IDisposable) != null;
if (canDisposable)
{
var dispose = typeOfObjectForDispose.GetMethod("Dispose");
dispose.Invoke(objectForDispose, new object[] { });
}
}
}