- 1
- 2
- 3
if (selectedGroup == null)
return null;
return selectedGroup;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+6
if (selectedGroup == null)
return null;
return selectedGroup;
зачем if то?
0
using Microsoft.VisualBasic.CompilerServices;
using System;
namespace ConsoleApplication2
{
[StandardModule]
internal sealed class Module1
{
[STAThread]
public static void Main()
{
label_0:
int num1;
int num2;
try
{
ProjectData.ClearProjectError();
num1 = 1;
label_1:
int num3 = 2;
Test.TTT();
goto label_8;
label_3:
num2 = num3;
switch (num1)
{
case 1:
int num4 = num2 + 1;
num2 = 0;
switch (num4)
{
case 1:
goto label_0;
case 2:
goto label_1;
case 3:
case 4:
goto label_8;
}
}
}
catch (Exception ex) when (ex is Exception & (uint) num1 > 0U & num2 == 0)
{
ProjectData.SetProjectError(ex);
goto label_3;
}
throw ProjectData.CreateProjectError(-2146828237);
label_8:
if (num2 == 0)
return;
ProjectData.ClearProjectError();
}
}
}
Вот какая жуть получилась при декомпиляции старого доброго On Error Resume Next из VB.
Исходный код:
Sub Main()
On Error Resume Next
TTT() 'определен в модуле Test
Exit Sub
End Sub
0
var languageCodes = locales
.GroupBy(l => l.Key.Substring(0, 2))
.Select(group => group.First())
.Select(l => new KeyValuePair<string, string>(l.Key.Substring(0, 2), l.Value))
.OrderBy(l => l.Value);
Прислала боевая подруга из Канады. Да, это продакшен. Но на этот раз код не падавана, а её собственный.
+5
private void sendCommand(Hi1Command command)
{
var aCommand = command as Hi1Command;
...
}
На случай если Microsoft откажется от строгой типизации С#
+2
private long m_IsExecuting;
// ...
public virtual void Execute(object parameter)
{
try
{
if (Interlocked.Read(ref m_IsExecuting) != 0)
return;
Interlocked.Increment(ref m_IsExecuting);
m_Execute(parameter);
}
finally
{
Interlocked.Decrement(ref m_IsExecuting);
}
}
А за то, что ты меня не пустил, я пущу следующего.
0
foreach (var r in rezList)
{
int newId = rnd.Next();
rez.Add(new FileItem()
{
Id = newId,
/* ..... */
});
}
Новый способ генерирования ID...
−1
_colorFlashlightAnimation = compositor.CreateExpressionAnimation(
"1.0 - min("
+ " 1.0,"
+ " ("
+ " ("
+ " ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )"
+ " * ( frame.Offset.x + (frame.Size.x * 0.5) + grid.Offset.x - (windowWidth * 0.5) )"
+ " ) + ("
+ " ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )"
+ " * ( frame.Offset.y + (frame.Size.y * 0.5) + grid.Offset.y - (windowHeight * 0.5) )"
+ " )"
+ " ) / ( radius * radius )"
+ ")");
Удивитесь, но это Microsoft
https://github.com/Microsoft/WindowsUIDevLabs/blob/master/Demos/SlideShow/SlideShow/TransitionLibrary.cs
+5
class Program {
static void Main(string[] args) {
AppInstance.Get().DoMain(IOMain);
}
static IO<None> IOMain() {
return
from _ in IO.Do(() => Console.WriteLine("What is your name?"))
from name in IO.Do(() => Console.ReadLine())
let message = "Hi, " + name + "!"
from r in IO.Do(() => Console.WriteLine(message))
select r;
}
}
https://habrahabr.ru/post/282940
+7
using System;
public class Test
{
private static void Main(string[] args)
{
int d = 2147483647;
Console.WriteLine(d);
long g = 2147483647+d;
Console.WriteLine(g);
long k = new MyClass() + new MyClass();
Console.WriteLine(k);
}
public class MyClass
{
public static implicit operator int(MyClass m)
{
return 5;
}
public static implicit operator long(MyClass m)
{
return 100;
}
}
}
Типушня
+2
public static long NormalizeIp(this long ip)
{
var ipAddress = new IPAddress(Math.Abs(ip)).ToString();
return ipAddress.IpToLong();
}
static long IpToLong(this string ip)
{
double num = 0;
if (!string.IsNullOrEmpty(ip))
{
var ipBytes = ip.Split('.');
for (var i = ipBytes.Length - 1; i >= 0; i--)
{
num += ((int.Parse(ipBytes[i]) % 256) * Math.Pow(256, (3 - i)));
}
}
return (long)num;
}
Получаем IP вот таким вот методом - BitConverter.ToInt32(IPAddress.Parse(ip) .GetAddressBytes(), 0)
Приводим к типу long (неявным методом, т.е. long a = ip_address) и в таком виде сохраняем в базу как bigint (int64)
Затем берем его из базы и пытаемся провернуть с ним вот такой NormalizeIp
Печаль (