- 1
- 2
- 3
- 4
string tmpS;
//идут всякие монипуляции с этой строкой
//. . .
tmpS.Remove(0, tmpS.Length);
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+120
string tmpS;
//идут всякие монипуляции с этой строкой
//. . .
tmpS.Remove(0, tmpS.Length);
Реальный код из коммерческого продукта.
+126
private const string constDefFeedLimitValue = "5";
private string feedLimit = constDefFeedLimitValue;
private int feedLmt;
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
try
{
feedLmt = Convert.ToInt32(feedLimit);
}
catch (Exception)
{
feedLmt = 0;
}
...
}
Автор из Киева, имеет статус MVP.
+119
Microsoft.Win32.RegistryKey Fregistry =
Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE")
.OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion")
.OpenSubKey("Installer").OpenSubKey("UserData")
.OpenSubKey("S-1-5-18").OpenSubKey("Products");
string []Names = Fregistry.GetSubKeyNames() ;
string uninstall = "";
string ApplicationName = "Adobe Reader 7.0.8";
for (int i = 0; i < Names.Length; i++)
{
Microsoft.Win32.RegistryKey FTemp = Fregistry.OpenSubKey(Names[i]).OpenSubKey("InstallProperties");
if (FTemp.GetValue("DisplayName").ToString() == ApplicationName)
{
object obj = FTemp.GetValue("UninstallString");
if (obj == null)
uninstall = "";
else
uninstall = obj.ToString();
i = Names.Length;
}
}
System.Console.WriteLine(uninstall);
System.Diagnostics.Process FProcess = new System.Diagnostics.Process();
string temp = "/x{" + uninstall.Split("/".ToCharArray())[1].Split("I{".ToCharArray())[2];
FProcess.StartInfo.FileName = uninstall.Split("/".ToCharArray())[0];
FProcess.StartInfo.Arguments = temp;
FProcess.StartInfo.UseShellExecute = false;
FProcess.Start();
System.Console.Read();
+131
static public int IIF(bool condition, int a, int b)
{
int x = 0;
if (condition)
{
x = a;
}
else
{
x = b;
}
return x;
}
static public bool IIF(bool condition, bool a, bool b)
{
bool x = false;
if (condition)
{
x = a;
}
else
{
x = b;
}
return x;
}
static public Single IIF(bool condition, Single a, Single b)
{
float x = 0;
if (condition)
{
x = a;
}
else
{
x = b;
}
return x;
}
static public Double IIF(bool condition, double a, double b)
{
double x = 0;
if (condition)
{
x = a;
}
else
{
x = b;
}
return x;
}
static public decimal IIF(bool condition, decimal a, decimal b)
{
decimal x = 0;
if (condition)
{
x = a;
}
else
{
x = b;
}
return x;
}
+146
case enter:
{
TreeNodeBackColorChange();
if (Connection.Login == "" || Connection.Login == null)
{
new fmlogin().ShowDialog();
try
{
if (Connection.Login != "")
foreach (TreeNode item in tvMenuList.Nodes)
{
if (item.Name == lk)
{
item.NodeFont = new Font("arial", 10, FontStyle.Bold);
item.Text += " (" + Connection.Login + ")";
}
}
}
catch { }
}
else MessageBox.Show("Вы уже авторизованы!", "Вход в личный кабинет", MessageBoxButtons.OK, MessageBoxIcon.Warning);
break;
}
case leave:
{
TreeNodeBackColorChange();
if (Connection.Login != "" && Connection.Login != null)
{
if (MessageBox.Show("Вы уверены, что хотите выйти?", "Выход", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Connection.Login = "";
Connection.Pass = "";
try
{
foreach (TreeNode item in tvMenuList.Nodes)
{
foreach (TreeNode item2 in item.Nodes)
{
foreach (TreeNode item3 in item2.Nodes)
{
if (item3.Name == lk)
{
item.NodeFont = tvMenuList.Font;
item3.Text = "Личный кабинет";
}
}
if (item2.Name == lk)
{
item.NodeFont = tvMenuList.Font;
item2.Text = "Личный кабинет";
}
}
if (item.Name == lk)
{
item.NodeFont = tvMenuList.Font;
item.Text = "Личный кабинет";
}
}
}
catch { }
MessageBox.Show("Выход произведен успешно!", "Выход", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else MessageBox.Show("Вы не авторизованы!", "Выход из личного кабинета", MessageBoxButtons.OK, MessageBoxIcon.Warning);
break;
}
извиняюсь) форматирование сбивается когда из студии вставляю)
PS жалко что нельзя вставить больше 100 строк. А тут такие красивые функции есть, которые теряют всю свою зрелишность при их урезании
+116
if (rbNewPackage.Checked)
{
var ls = from ent in Program.DB.UserInfos
where
(from rp in Program.DB.ReceivedPackages
join r in Program.DB.RecordBooks on rp.id equals r.id_package
where rp.id_user == ent.id &&
r.date == (from recb in Program.DB.RecordBooks
join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
where recp.id_user == ent.id
select recb.date).Max() && r.id_status == 1
select rp).Count() != 0
select ent;
grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
}
else if (rbCancelled.Checked)
{
var ls = from ent in Program.DB.UserInfos
where
(from rp in Program.DB.ReceivedPackages
join r in Program.DB.RecordBooks on rp.id equals r.id_package
where rp.id_user == ent.id &&
r.date == (from recb in Program.DB.RecordBooks
join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
where recp.id_user == ent.id
select recb.date).Max() && r.id_status == 5
select rp).Count() != 0
select ent;
grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
}
else if (rbConditional.Checked)
{
var ls = from ent in Program.DB.UserInfos
where
(from rp in Program.DB.ReceivedPackages
join r in Program.DB.RecordBooks on rp.id equals r.id_package
where rp.id_user == ent.id &&
r.date == (from recb in Program.DB.RecordBooks
join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
where recp.id == rp.id
select recb.date).Max() && r.id_status == 3
select rp).Count() != 0
select ent;
grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
}
else if (rbOfficial.Checked)
{
var ls = from ent in Program.DB.UserInfos
where
(from rp in Program.DB.ReceivedPackages
join r in Program.DB.RecordBooks on rp.id equals r.id_package
where rp.id_user == ent.id &&
r.date == (from recb in Program.DB.RecordBooks
join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
where recp.id == rp.id
select recb.date).Max() && r.id_status == 4
select rp).Count() != 0
select ent;
grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
}
говногод моего бывшего коллеги по работе))
+118
foreach (var aiett in _selectApplItemEntranceTrial)
{
lbl2:
ReceptionReason_EducationLayout rrel_temp = null;
EntranceTrialItem_RecResEducLayout eti_rrel = null;
bool flag = false;
foreach (var rrel in _recReasonEducLay)
foreach (var ap in aiett.ListAppItem)
foreach (var rr in rrel.ListRecReas_EducLayout)
if (ap.ApplItem.Id_ReceptionReason_EducationLayout == rr.Id)
{
rrel_temp = rr;
eti_rrel = rrel;
flag = true;
goto lbl;
}
lbl: ;
if (flag)
{
_recReasonEducLay.FirstOrDefault(x => x == eti_rrel).ListRecReas_EducLayout.Remove(rrel_temp);
if (_recReasonEducLay.FirstOrDefault(x => x == eti_rrel).ListRecReas_EducLayout.Count == 0)
_recReasonEducLay.Remove(eti_rrel);
goto lbl2;
}
}
Мой личный говнокод! Работающий правильно))))
+124
while (!Pr.HasExited) System.Threading.Thread.Sleep(250);
Ожидание завершения запущенного процесса
+115
RepaymentEvent e = DatabaseHelper.GetString("event_type", pReader) == "RBLE"
? new BadLoanRepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
: (DatabaseHelper.GetString("event_type", pReader) == "RRLE"
? new RescheduledLoanRepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
:(DatabaseHelper.GetString("event_type", pReader).StartsWith("P")
? new PendingRepaymentEvent (DatabaseHelper.GetString("event_type", pReader)) {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
: new RepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}));
Вот такую "элегантную" строчку нашел сегодня коллега в коде нашего проекта :)
Создаем событие пойди разбери какое :)
+112
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\origLocation\");
DirectoryInfo destDir = new DirectoryInfo(@"C:\Users\origLocation\destLocation\");
FileInfo[] newVerFiles = dir.GetFiles("*.TXT");
foreach (FileInfo newVerFile in newVerFiles)
{
Regex regex = new Regex("\\d+-new-ver.TXT", RegexOptions.IgnoreCase);
if (regex.IsMatch(newVerFile.Name))
{
newVerFile.MoveTo(destDir.FullName);
}
}