
| class Program { static void Main(string[] args) { List for(int i = 0; i < 3; ++i) { MemberToCompare toInsert = new MemberToCompare(1); if(!group.Contains(toInsert)) group.Add(toInsert); } Console.WriteLine(group.Count + " elementos inseridos!"); Console.ReadLine(); } } class MemberToCompare: IComparable { public int test; public MemberToCompare(int i) { test = i; } public int CompareTo(object obj) { MemberToCompare other = obj as MemberToCompare; if (other == null) { return -1; } if (other.test == test) return 0; else return 1; } } |
private Dictionary private delegate string DelegateFunction(); public Ctor() { connectorMapper = new Dictionary connectorMapper.Add(-1, new DelegateFunction(NegativeValue)); connectorMapper.Add(1, new DelegateFunction(PositiveValue)); } private string NegativeValue() { return "Valor negativo"; } private string { return "Valor positivo"; } private void CalcFunction() { //uma função qualquer que retorne 1 ou -1 int indexer = FuncaoComplexa() DelegateFunction func = connectorMapper[indexer]; Console.WriteLine( "Entrou na função com: " + func() ); } |
| int xPoint = 0, yPoint = 0; double xDraw = 1, yDraw = 10; private static void NextDrawPoint(ref int xPoint, ref int yPoint, ref double xDraw, ref double yDraw) { ++xPoint; yPoint += Convert.ToInt32(Math.Floor((double)xPoint / 3)); xPoint %= 3; xDraw += 3; yDraw -= Math.Floor(xDraw / 9) * 1.5; xDraw %= 9; } |