Procurar
Últimos assuntos
Top dos mais postadores
Nilton | ||||
pekisalto | ||||
Edward Phoenix | ||||
Michel Sosa | ||||
alexpfz | ||||
Paulo-Smith | ||||
Dj Nando Phoenix | ||||
Cesariolange | ||||
allanyo | ||||
Gabriel Padilha |
Guardando Varios valores numa variavel - C#
Página 1 de 1
Guardando Varios valores numa variavel - C#
ola!..
Mais um dos meus codigos loucos ahahah...
Esse codigo serve para guardar varios dados numericos dentro de uma só variavel...
O Uso de array's é um pouco complicado no começo..
Mas deem uma olhada:
OBS: Insira um textbox,uma listbox,dois buttons (O Button calcular deve iniciar com a propriedade enabled falsa) e duas labels;
-------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//Declarei como publica a variavel contendo o array como inteira,a letra n
public int[] n = new int[5];
public int i = 0;
//Result como inteira tambem mas publica
public int result1 = 0;
//
public Form1()
{
//Inicializando matrizes como 0
n[0] = 0;
n[1] = 0;
n[2] = 0;
n[3] = 0;
n[4] = 0;
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
button2.Text = "Inserir";
label1.Text = "";
{
if (listBox1.Text.Length == 0)
{
MessageBox.Show("Escolha um numero!");
}
else
{
int c = Convert.ToInt32(this.listBox1.Text);
int b = Convert.ToInt32(this.textBox1.Text);
b = c;
{
if (c < 0)
{
MessageBox.Show("Nao aceito numeros negativos");
this.Close();
}
}
{
//Se a matriz n[0] for zerada entao inserir o valor de b que no caso é a textbox e zerar a text box
if (n[0] == 0)
{
n[0] = b;
b = 0;
}
}
{
if (n[1] == 0)
{
n[1] = b;
b = 0;
}
}
{
if (n[2] == 0)
{
n[2] = b;
b = 0;
}
}
{
if (n[3] == 0)
{
n[3] = b;
b = 0;
}
}
{
if (n[4] == 0)
{
n[4] = b;
b = 0;
}
}
{
//Se matriz 0 1 2 3 e 4 for diferente de 0 entao
if (n[0] != 0 && n[1] != 0 && n[2] != 0 && n[3] != 0)
{
//Mudar o texto do button para "calcular"
button2.Text = "Calcular!";
}
}
{
//Se matriz 1 ou 2 ou 3 ou 4 forigual a zero
if (n[0] == 0 || n[1] == 0 || n[2] == 0 || n[3] == 0 || n[4] == 0)
{
//Na medida que o usuario vai adicionando numeros ele vai mostrando numa label
label2.Text = ("" + n[0] + "," + n[1] + "," + n[2] + "," + n[3]);
//Efetua o calculo das matrizes
result1 = (n[0] + n[1] + n[2] + n[3] + n[4]) / 2;
}
else
{
//Exibir o resultado final
label1.Text = ("A media é: " + result1);
//Mudar o text do button para RONALDO
button2.Text = "RONALDOoOo!";
//Zera as variaveis
n[0] = 0;
n[1] = 0;
n[2] = 0;
n[3] = 0;
n[4] = 0;
}
}
}
}
}
}
}
------
Limitei a variavel para 5 numeros...
Mas ela pode ser maior dependendo da situação ^^
Puta dor de cabeça....Quem tiver duvida UPA ae vai ¬¬'
faloo!..
Tudo de minha AUTORIA!!!!
PHOENIX E NAO O PAGA PAU DJ PHOENIX ( GORDIN VIADDOO ) hahahaha!!
FALO!
Mais um dos meus codigos loucos ahahah...
Esse codigo serve para guardar varios dados numericos dentro de uma só variavel...
O Uso de array's é um pouco complicado no começo..
Mas deem uma olhada:
OBS: Insira um textbox,uma listbox,dois buttons (O Button calcular deve iniciar com a propriedade enabled falsa) e duas labels;
-------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
//Declarei como publica a variavel contendo o array como inteira,a letra n
public int[] n = new int[5];
public int i = 0;
//Result como inteira tambem mas publica
public int result1 = 0;
//
public Form1()
{
//Inicializando matrizes como 0
n[0] = 0;
n[1] = 0;
n[2] = 0;
n[3] = 0;
n[4] = 0;
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
button2.Text = "Inserir";
label1.Text = "";
{
if (listBox1.Text.Length == 0)
{
MessageBox.Show("Escolha um numero!");
}
else
{
int c = Convert.ToInt32(this.listBox1.Text);
int b = Convert.ToInt32(this.textBox1.Text);
b = c;
{
if (c < 0)
{
MessageBox.Show("Nao aceito numeros negativos");
this.Close();
}
}
{
//Se a matriz n[0] for zerada entao inserir o valor de b que no caso é a textbox e zerar a text box
if (n[0] == 0)
{
n[0] = b;
b = 0;
}
}
{
if (n[1] == 0)
{
n[1] = b;
b = 0;
}
}
{
if (n[2] == 0)
{
n[2] = b;
b = 0;
}
}
{
if (n[3] == 0)
{
n[3] = b;
b = 0;
}
}
{
if (n[4] == 0)
{
n[4] = b;
b = 0;
}
}
{
//Se matriz 0 1 2 3 e 4 for diferente de 0 entao
if (n[0] != 0 && n[1] != 0 && n[2] != 0 && n[3] != 0)
{
//Mudar o texto do button para "calcular"
button2.Text = "Calcular!";
}
}
{
//Se matriz 1 ou 2 ou 3 ou 4 forigual a zero
if (n[0] == 0 || n[1] == 0 || n[2] == 0 || n[3] == 0 || n[4] == 0)
{
//Na medida que o usuario vai adicionando numeros ele vai mostrando numa label
label2.Text = ("" + n[0] + "," + n[1] + "," + n[2] + "," + n[3]);
//Efetua o calculo das matrizes
result1 = (n[0] + n[1] + n[2] + n[3] + n[4]) / 2;
}
else
{
//Exibir o resultado final
label1.Text = ("A media é: " + result1);
//Mudar o text do button para RONALDO
button2.Text = "RONALDOoOo!";
//Zera as variaveis
n[0] = 0;
n[1] = 0;
n[2] = 0;
n[3] = 0;
n[4] = 0;
}
}
}
}
}
}
}
------
Limitei a variavel para 5 numeros...
Mas ela pode ser maior dependendo da situação ^^
Puta dor de cabeça....Quem tiver duvida UPA ae vai ¬¬'
faloo!..
Tudo de minha AUTORIA!!!!
PHOENIX E NAO O PAGA PAU DJ PHOENIX ( GORDIN VIADDOO ) hahahaha!!
FALO!
Edward Phoenix- Mensagens : 34
Pontos : 86
Data de inscrição : 22/02/2010
Idade : 33
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos
|
|
2011-11-10, 13:52 por allanyo
» matriz em c
2011-11-08, 19:02 por allanyo
» matriz em c
2011-11-08, 19:02 por allanyo
» [FUNÇÃO] C
2011-09-25, 15:33 por lucas150992
» Comprare Viagra. da mulher viagra generico
2011-08-04, 09:16 por Convidado