string random = "1";
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
try {
User.ClaimToken();
}
catch {
User.ClaimToken();
}
/// <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());
}
public void Handle(SomethingCreatedEvent e)
{
if (e.ActCode == "SOME_VALUE")
{
return;
}
else
{
// insert real function body here
}
}
if ( x == true)
{
// do something
}
Fucking amateurs :| lol
i++;
i++;
i++;
i++;
Console.WriteLine(i);
He doesn't know what is " i+=4 " :||||
if ( variable )
{
}
else
{
Console.WriteLine("Wrong")
}
He doesn't know what "Not" is it :|
string str = Console.ReadLine();
string len = 0;
for(int i = 0; i < str.Length; i++)
{
len++;
}
Let's get string length :| Dummy
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
/// <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
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()
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.
public static bool HasValues<T>(this ICollection<T> collection)
{
if (collection == null)
{
return false;
}
if (collection.Count == 0)
{
return false;
}
return true;
}
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, "%");
}
}