Skip to content

Instantly share code, notes, and snippets.

@bergpb
Created August 19, 2020 19:37
Show Gist options
  • Select an option

  • Save bergpb/f667d013327d6ff81d9ad9a09fd1f4f5 to your computer and use it in GitHub Desktop.

Select an option

Save bergpb/f667d013327d6ff81d9ad9a09fd1f4f5 to your computer and use it in GitHub Desktop.
Exemplo de Extension Methods in C#
using System.Globalization
namespace System
{
static class DateTimeExtensions
{
public static string ElapsedTime(this Datime thisObj)
{
TimeSpan duration = DateTime.Now.Subtract(thisObj);
if(duration.TotalHours < 24.0)
{
return duration.TotalHours.ToString("F1", CultureInfo.InvariantCulture) + " hours";
}
else
{
return duration.TotalDays.ToString("F1", CultureInfo.InvariantCulture) + " days";
}
}
}
}
using System
public class ProcessFile
{
public static void Main()
{
DateTime dt = new DateTime(2018, 11, 16, 8, 10, 45);
Console.WriteLine(dt.ElapsedTime());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment