string random = "1";
By Anonymous, 2018-01-11 20:23:55
class {
    public State state;
    //enums cant take double values...
    public struct State
    {
        public const float IDLE = 0f;
        public const float WALKING = 0.5f;
        public const float RUNNING = 1f;
    }
    protected void Stop()
    {
        SetSpeed(State.IDLE);
    }
    protected void SetSpeed(float f)
    {
        agent.speed = f;
        if (agent.speed > 1f && agent.speed < 5f)
        {
            f = State.WALKING;
            agent.Resume();
        }
        else if (agent.speed > 5f)
        {
            f = State.RUNNING;
            agent.Resume();
        }
        else
        {
            f = State.IDLE;
            agent.Stop();
        }
    }
}

Who needs static float when you can have a constant in a nested struct, as a bonus State state has 0 references in the project

By SwagridOfficial, 2018-01-05 13:39:24
try {
    User.ClaimToken();
} 
catch {
    User.ClaimToken();
}
By Anonymous, 2017-12-22 08:44:59
/// <summary>
/// Method that checks if an object is not null
/// </summary>
/// <param name="obj">extend type of <see cref="Object"/></param>
/// <returns>true if object is not null</returns>
public static bool NotNull(this Object obj)
{
    return obj != null;
}


[TestMethod]
public void Test_Something()
{
    // test
    var result = DoSomething();
    
    // assert
    Assert.IsTrue(result.NotNull());
}
By Anonymous, 2017-12-21 15:42:20
public void Handle(SomethingCreatedEvent e)
{
    if (e.ActCode == "SOME_VALUE")
    {
        return;
    }
    else
    {
        // insert real function body here
    }
}
By Anonymous, 2017-12-20 15:40:49
if ( x == true)
{
    // do something
}

Fucking amateurs :| lol

By Manoochehr Mojgani, 2017-12-19 10:03:29
i++;
i++;
i++;
i++;
Console.WriteLine(i);

He doesn't know what is " i+=4 " :||||

By Manoochehr Mojgani, 2017-12-13 21:46:04
if ( variable )
{
    
}
else
{
    Console.WriteLine("Wrong")
}

He doesn't know what "Not" is it :|

By Manoochehr Mojgani, 2017-12-13 17:05:36
string str = Console.ReadLine();
string len = 0;
for(int i = 0; i < str.Length; i++)
{
    len++;
}

Let's get string length :| Dummy

By Manoochehr Mojgani, 2017-12-13 16:47:11
class ExampleClass {
    public void DoSomething()
    {
       if (this != null) {
           //omitted
       }
    }
    
    public void DoSomething2()
    {
       if (this != null) {
           //omitted
       }
    }
    
}

Explanation: This can't be null in C# virtual instance methods - I was so confused by the widespread use of this check that I asked this question at SO: https://stackoverflow.com/questions/31747718/can-this-be-null-in-c-sharp-virtual-methods-what-happens-with-the-rest-of-ins

By Michail Michailidis, 2017-12-13 14:54:58
/// <summary>
/// Returns true if any component of of Vector3 v is negative
/// </summary>
public static bool Ext_IsNegative(this Vector3 v)
{
    return v.x < 0f && v.y < 0f && v.z < 0f;
}

Either the description is wrong or the method in itself

By SwagridOfficial, 2017-12-13 13:00:34
var list = new List<string>() { // Assume some items in the list };

for (var i = 0; i < list.Count; i++)
{
    var item = list[i];
    list.Remove(item);
    
    i--;
}

Simple alternative to List.Clear()

By Taylor, 2017-12-13 07:07:56
protected void EnableEditButtons(bool Value)
{
    if (Value == false)
    {
        buttonAdd.Disabled = true;
        buttonDelete.Disabled = true;
    }
    else
    {
        buttonAdd.Disabled = false;
        buttonDelete.Disabled = false;
    }
}

// ...

if (IsEditable(ID))
    EnableEditButtons(true);
else
    EnableEditButtons(false);

I found this old code in an app I was updating for a client a number of years back. It was so good I documented it on my own blog.

By Jon Hartmann, 2017-12-12 17:09:54
public static bool HasValues<T>(this ICollection<T> collection)
{
    if (collection == null)
    {
        return false;
    }
    if (collection.Count == 0)
    {
        return false;
    }
    return true;
}
By oskarnrk, 2017-12-12 16:49:43
    public static class DecimalHelpers
    {
        /// <summary>
        /// Format a decimal XX.XX to XX,XX%.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string FormatToStringPercentageValue(this decimal value)
        {
            return value.ToString().Replace(".", ",").FormatToPercentageValue();
        }
    }
    
    public static class StringHelpers
    {
        /// <summary>
        /// Add % at the end of the string.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string FormatToPercentageValue(this string value)
        {
            return string.Concat(value, "%");
        }
    }
By Anonymous, 2017-12-12 10:58:38