using System;
namespace Articulo.CSharp.MetodosExtension
{
// Definición de la enumeración:
public enum Notas
{
F = 0,
D = 1,
C = 2,
B = 3,
A = 4
}
// Clase estática con métodos de extensión
// para la enumeración `Notas`:
public static class ExtensionesNotas
{
// Representa la nota mínima para pasar un examen:
public static Notas NotaMinima = Notas.D;
// Determina si la nota dada para un estudiante
// supera o iguala la nota mínima:
public static bool Paso (this Notas nota)
{
return nota >= NotaMinima;
}
}
public sealed class EnumeracionMetodosExtension
{
public static void Main()
{
Notas nota1 = Notas.D;
Notas nota2 = Notas.F;
Console.WriteLine("\n¿Con la nota `D` pasa?: {0}", nota1.Paso() ? "Sí" : "No");
Console.WriteLine("¿Con la nota `F` pasa?: {0}\n", nota2.Paso() ? "Sí" : "No");
}
}
}
dXNpbmcgU3lzdGVtOwoKbmFtZXNwYWNlIEFydGljdWxvLkNTaGFycC5NZXRvZG9zRXh0ZW5zaW9uCnsKICAgIC8vIERlZmluaWNpw7NuIGRlIGxhIGVudW1lcmFjacOzbjoKICAgIHB1YmxpYyBlbnVtIE5vdGFzCiAgICB7CiAgICAgICAgRiA9IDAsIAogICAgICAgIEQgPSAxLCAKICAgICAgICBDID0gMiwgCiAgICAgICAgQiA9IDMsIAogICAgICAgIEEgPSA0CiAgICB9CiAgICAKICAgIC8vIENsYXNlIGVzdMOhdGljYSBjb24gbcOpdG9kb3MgZGUgZXh0ZW5zacOzbiAKICAgIC8vIHBhcmEgbGEgZW51bWVyYWNpw7NuIGBOb3Rhc2A6CiAgICBwdWJsaWMgc3RhdGljIGNsYXNzIEV4dGVuc2lvbmVzTm90YXMKICAgIHsKICAgICAgICAvLyBSZXByZXNlbnRhIGxhIG5vdGEgbcOtbmltYSBwYXJhIHBhc2FyIHVuIGV4YW1lbjoKICAgICAgICBwdWJsaWMgc3RhdGljIE5vdGFzIE5vdGFNaW5pbWEgPSBOb3Rhcy5EOwogICAgICAgIAogICAgICAgIC8vIERldGVybWluYSBzaSBsYSBub3RhIGRhZGEgcGFyYSB1biBlc3R1ZGlhbnRlIAogICAgICAgIC8vIHN1cGVyYSBvIGlndWFsYSBsYSBub3RhIG3DrW5pbWE6CiAgICAgICAgcHVibGljIHN0YXRpYyBib29sIFBhc28gKHRoaXMgTm90YXMgbm90YSkKICAgICAgICB7CiAgICAgICAgICAgIHJldHVybiBub3RhID49IE5vdGFNaW5pbWE7CiAgICAgICAgfQogICAgfQogICAgCiAgICBwdWJsaWMgc2VhbGVkIGNsYXNzIEVudW1lcmFjaW9uTWV0b2Rvc0V4dGVuc2lvbgogICAgewogICAgICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKCkKICAgICAgICB7CiAgICAgICAgICAgIE5vdGFzIG5vdGExID0gTm90YXMuRDsKICAgICAgICAgICAgTm90YXMgbm90YTIgPSBOb3Rhcy5GOwogICAgICAgICAgICBDb25zb2xlLldyaXRlTGluZSgiXG7Cv0NvbiBsYSBub3RhIGBEYCBwYXNhPzogezB9Iiwgbm90YTEuUGFzbygpID8gIlPDrSIgOiAiTm8iKTsKICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIsK/Q29uIGxhIG5vdGEgYEZgIHBhc2E/OiB7MH1cbiIsIG5vdGEyLlBhc28oKSA/ICJTw60iIDogIk5vIik7CiAgICAgICAgfQogICAgfQp9