- 1
- 2
- 3
- 4
- 5
bool isInsideString = false;
...
isInsideString = (isInsideString == true)? false:true;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+136
bool isInsideString = false;
...
isInsideString = (isInsideString == true)? false:true;
+110
public partial class ProductForm : Form
{
private delegate bool ProductManipulation();
private static ProductManipulation pmd;
public ProductForm()
{
InitializeComponent();
this.FormClosing += this.ProductForm_Closing;
ProductsLB.DoubleClick += this.ChangeBtn_Click;
ProductsLB.Click += this.LoadProductKey;
pmd = LoadDataToLB;
pmd();
}
...
private void AddBtn_Click(object sender, EventArgs e)
{
pmd -= LoadDataToLB;
pmd += AddProduct + pmd;
pmd += LoadDataToLB;
pmd();
pmd -= AddProduct;
}
...
Обильное делегирование
+131
Note that async is a contextual keyword. In all syntactic contexts other than the ones above it is considered an identifier.
Thus, the following is allowed (though strongly discouraged!):
using async = System.Threading.Tasks.Task;
…
async async async(async async) { }
Из C# Specifications к Visual Studio Async CTP.
+127
string res = "";
try
{
if (org_id == NewId.ToString())
{
string query = "delete from ARMVZ_CONFIG where org_id = " + org_id;
OdbcCommand cmd = new OdbcCommand(query, getConnect());
cmd.ExecuteNonQuery();
cmd.CommandText = "delete from organisations where id = " + org_id;
cmd.ExecuteNonQuery();
cmd.CommandText = "delete from services where orgid = " + org_id;
cmd.ExecuteNonQuery();
NewId = 0;
res = "";
}
else
{
try
{
string query = "select * from tmp_organisations where id = " + org_id;
OdbcCommand cmd = new OdbcCommand(query, getConnect());
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
if (dt.Rows.Count > 0)
{
query = "update organisations set ";
foreach (DataColumn col in dt.Columns)
{
if (col.ColumnName != "id")
{
query = query + col.ColumnName +
" = (select " + col.ColumnName +
@" from tmp_organisations where tmp_organisations.id = " + org_id + " ),";
}
}
query = query.Remove(query.Length - 1);
query = query + " where id = " + org_id;
cmd.CommandText = query;
dt.Dispose();
cmd.ExecuteNonQuery();
}
}
catch
{
//
}
try
{
string query = "select * from tmp_armvz_config where org_id = " + org_id;
OdbcCommand cmd = new OdbcCommand(query, getConnect());
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
if (dt.Rows.Count > 0)
{
query = "update armvz_config set ";
foreach (DataColumn col in dt.Columns)
{
if (col.ColumnName != "org_id")
{
query = query + col.ColumnName +
" = (select " + col.ColumnName +
@" from tmp_armvz_config where tmp_armvz_config.org_id = " + org_id + " ),";
}
}
query = query.Remove(query.Length - 1);
query = query + " where org_id = " + org_id;
cmd.CommandText = query;
dt.Dispose();
cmd.ExecuteNonQuery();
}
}
catch
{
//
}
метод называется "rollback_transaction". весь метод просто не влез
+119
static int getCheckNumber(int n)
{
return Average(n, 0); //Сабж
}
static int Average(int x, int y) //Функция вычисления среднего арифметического
{
return ((x + y) / 2);
}
Среднее арифметическое от произвольной переменной и нуля - эквивалентно делению на 2 :)
+118
private Excel._Application _excel;
...
private void RefreshFormulas(FormulaRefreshOption formulaRefreshOption, object objectToRefresh)
{
//Где-то в дебрях километрового метода бросилось в глаза
...
try
{
Excel.Range intersection = selection, selection2 = selection;
while (selection2 != null)
{
intersection = _excel.Intersect(selection2, selection2.Dependents,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
System.Windows.Forms.Application.DoEvents();
excelUtilities.RecalculateRangeInstance(true, intersection/*_excel.Selection as Excel.Range*/);
selection2 = intersection;
}
}
catch (Exception) { /*ignore the exception because .Dependents will throw an exception if there aren't any dependents*/}
...
}
+122
while (!requestedTermination)
{
// ...
// тут 130 строк кода...
// ...
if (requestedTermination)
{
break;
}
else
{
// to prevent excess CPU usage
Thread.Sleep(100);
}
}
requestedTermination - Property, изменяемое другим потоком
Мораль: не пишите длинные циклы - к концу цикла забудете, какое у него было условие завершения.
+133
/// <summary>
/// Abs function
/// </summary>
private static object Abs(List<Expression> p)
{
return Math.Abs(p[0]);
}
/// <summary>
/// Acos function
/// </summary>
private static object Acos(List<Expression> p)
{
return Math.Acos(p[0]);
}
/// <summary>
/// Asin function
/// </summary>
private static object Asin(List<Expression> p)
{
return Math.Asin(p[0]);
}
/// <summary>
/// Atan function
/// </summary>
private static object Atan(List<Expression> p)
{
return Math.Atan(p[0]);
}
/// <summary>
/// Atan2 function
/// </summary>
private static object Atan2(List<Expression> p)
{
return Math.Atan2(p[0], p[1]);
}
Кусок кода от "Капитана Очевидность"
+146
public ActionResult RenderDesigner()
{
// Get the received text
var received = string.Empty;
using(var reader = new StreamReader(Request.InputStream))
{
received = reader.ReadToEnd();
}
// Possible texts received
var xml = "";
var id = "";
var moveId = "";
int distance = 0;
// Get all string from received
var keys = received.Split('&');
for (var i = 0; i < keys.Length; i++)
{
// XML
if(keys[i].StartsWith("xml="))
{
xml = Server.UrlDecode(keys[i].Split('=')[1]);
}
// ID
else if (keys[i].StartsWith("id="))
{
id = keys[i].Split('=')[1];
}
// Position
else if (keys[i].StartsWith("distance="))
{
distance = int.Parse(keys[i].Split('=')[1]);
}
// Move ID
else if (keys[i].StartsWith("moveId="))
{
moveId = keys[i].Split('=')[1];
}
}
}
разбор параметров POST запроса в стиле MVC
+122
Controller.cs
public ActionResult SomeAction()
{
return View("My message");
}
SomeAction.cshtml
@{
Layout = null;
}
@Html.Raw(string.Format("{0}", Model.ToString()))
Да, это ASP.Net MVC