Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Trabalhando_com_Genericos_28._05._2015
- {
- class Program
- {
- class VetorGenérico<T> where T : IComparable
- {
- private T[] Vetor;
- public VetorGenérico()
- {
- Vetor = new T[10];
- }
- public void EntraElemento(int Pos, T Elemento)
- {
- Vetor[Pos] = Elemento;
- }
- public T AchaMaior()
- {
- T Maior = Vetor[0];
- for (int i = 1; i < 10; i++)
- {
- if (Vetor[i].CompareTo(Maior)>0)
- {
- Maior = Vetor[i];
- }
- }
- return Maior;
- }
- }
- static void Main(string[] args)
- {
- VetorGenérico<int> MeuVetorInt = new VetorGenérico<int>();
- MeuVetorInt.EntraElemento(0, 34);
- MeuVetorInt.EntraElemento(1, 43);
- MeuVetorInt.EntraElemento(2, 12);
- MeuVetorInt.EntraElemento(3, 55);
- MeuVetorInt.EntraElemento(4, 31);
- MeuVetorInt.EntraElemento(5, 40);
- MeuVetorInt.EntraElemento(6, 76);
- MeuVetorInt.EntraElemento(7, 55);
- MeuVetorInt.EntraElemento(8, 22);
- MeuVetorInt.EntraElemento(9, 15);
- Console.WriteLine("Maior Número: " + MeuVetorInt.AchaMaior().ToString());
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement