- 1
- 2
- 3
- 4
if (Expires != 0 && Expires.ToString() != "9223372036854775807")
{
...
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+3
if (Expires != 0 && Expires.ToString() != "9223372036854775807")
{
...
}
Expires типа long
+5
public string GenerateKey(int length)
{
System.Random random = new System.Random();
char[] chArray = new char[62]
{
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
'W',
'X',
'Y',
'Z',
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
'u',
'v',
'w',
'x',
'y',
'z',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9'
};
string str = string.Empty;
for (int index = 0; index < length; ++index)
str += (string) (object) chArray[random.Next(0, 35)];
return str;
}
Решил декомпилировать "Копатель Онлайн" ради лулзов.
+5
using static System.Console;
namespace OptimizationDetector
{
public static class OptimizationDetector
{
private static class pls
{
public static bool wtf = true;
}
private static int rly = detect();
private static int detect()
{
pls.wtf = false;
return 0;
}
public static bool IsOptimizationEnabled
{
get { return pls.wtf; }
}
}
class Program
{
static void Main(string[] args)
{
WriteLine($"\"Optimize code\" is enabled: {OptimizationDetector.IsOptimizationEnabled}");
ReadKey();
}
}
}
ОПТИМИЗИРОВАНО
+3
Оффтоп
Пишу либу для гуя в консоли. Столкнулся с проблемой медленного вывода в консоль на линуксе.
На винде есть няшный WriteConsoleOutput, который может вывести буфер разом на консоль, в линупсе ничего подобного не нашел.
Если использовать Console.WriteLine или libc-шный puts, все лагает неимоверно
Есть идеи?
+2
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Script.Serialization;
namespace Govnokod
{
public class Program
{
private static string input;
private static string[] inputargs;
private static int inputargsh = 0;
private static int eax;
private static string hax,hbx;
public static void CommandActions()
{
if (inputargs[0] == "download")
{
if (inputargsh > 1)
{
hax = inputargs[1];
hbx = (inputargsh > 2) ? inputargs[2]:null;
if (String.IsNullOrEmpty(hbx))
hbx = Environment.CurrentDirectory+"\\"+hax;
Console.WriteLine("Downloading...");
}
else Console.WriteLine("invalid argument: 1\n");
}
else if (inputargs[0] == "apkinfo")
{
if (inputargsh > 1)
{
Console.WriteLine("Apkinfo...");
}
else Console.WriteLine("invalid argument: 1\n");
}
else if (input != "")
Console.WriteLine("invalid command: "+input+"\n");
CommandStart();
}
public static void CommandStart()
{
if (inputargsh != 0)
{
Array.Clear(inputargs,0,inputargsh);
inputargsh = 0;
}
input = Console.ReadLine();
input = input.Trim();
hax = input.ToLower();
while (true)
{
eax = hax.IndexOf(' ');
Array.Resize(ref inputargs,inputargsh+1);
if (eax != -1)
{
inputargs[inputargsh] = hax.Substring(0,eax);
hax = hax.Substring(eax);
hax = hax.TrimStart();
inputargsh++;
}
else
{
inputargs[inputargsh] = hax;
inputargsh++;
hax = null;
break;
}
}
if (inputargs[0] == "quit")
{
Console.Clear();
Console.Write("Press any key to quit...");
Console.ReadKey();
}
else CommandActions();
}
public static void Main(string[] args)
{
Console.WriteLine("; Commands:");
Console.WriteLine(";\tdownload <apk> <path>");
Console.WriteLine(";\tapkinfo <apk> or <index>");
Console.WriteLine(";\tquit <>\n");
CommandStart();
}
}
}
"Распознователь Команд 6120"
+6
habrahabr.ru/post/113215/
Кодогенерируем вместе!
+5
public override TItem[] ToArray()
{
TItem[] arr = new TItem[Count];
Int64 i = 0;
foreach (TItem item in this)
{
if (i >= Count) break;
arr[i] = item;
i++;
}
return arr;
}
И пофиг, что foreach и так не даст превысить размер коллекции, всё равно проверим!
+4
public static void Test(__arglist)
{
}
public static void Text2(ref string str)
{
var reftype = __reftype(new TypedReference());
var refvalue = __refvalue(new TypedReference(), string) = "string";
var makeref = __makeref(str);
}
Ты не поверишь, но это реально C#
+2
public void CreateRow()
{
allow = true;
this.Height = this.Height;
allow = false;
}
private void MyWindow_SizeChanged(object sender, SizeChangedEventArgs e)
{
if (!allow)
{
MyGrid.RowDefinitions.Add(new RowDefinition());
return;
}
else
//нормальная реализация
}
Такой незамысловатый костыль в WPF
+4
public bool IsNormal() {
return Type == TypeOfWord.Normal;
}
public bool IsNumber() {
return Type == TypeOfWord.Number;
}
public bool IsOperator() {
return Type == TypeOfWord.Operator;
}
public bool IsBracket() {
return Type == TypeOfWord.Bracket;
}
public bool IsSymbol() {
return IsOperator() || IsBracket();
}
public bool IsSpace() {
return Type == TypeOfWord.Space;
}
public bool IsComment() {
return Type == TypeOfWord.Comment;
}
public bool IsExcess() {
return IsComment() || IsSpace();
}
public bool IsQuotedText() {
return Type == TypeOfWord.QuotedText;
}
public bool IsQuotedChar() {
return Type == TypeOfWord.QuotedChar;
}
public bool IsQuotedTextOrChar() {
return IsQuotedText() || IsQuotedChar();
}
public bool IsUnknown() {
return Type == TypeOfWord.Unknown;
}