Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 34543;PRIMEIRA PESSOA;230778;CASADO;BANCARIO
- 23543;SEGUNDA PESSOA;12051985;CASADO;ADMINISTRADOR DE EMPRESAS
- 36116;TERCEIRA PESSOA;04081954;DIVORCIADO;APOSENTADO/PENSIONISTA
- 52455;QUARTA PESSOA;16111987;CASADO;ARTESAO
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MeuPrimeiroLeitorDeArquivo
- {
- public class Cidadao
- {
- public int numeroRegistro { get; set; }
- public string nomeCompleto { get; set; }
- public string dataNascimento { get; set; }
- public string estadoCivil { get; set; }
- public string profissao { get; set; }
- public Cidadao (int nrRegistro, string nmCompleto, string dtNasc, string estCivil, string prfs)
- {
- this.numeroRegistro = nrRegistro;
- this.nomeCompleto = nmCompleto;
- this.dataNascimento = dtNasc;
- this.estadoCivil = estCivil;
- this.profissao = prfs;
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace MeuPrimeiroLeitorDeArquivo
- {
- public partial class FormPrincipal : Form
- {
- private List<Cidadao> cidadaos = new List<Cidadao>();
- public FormPrincipal()
- {
- InitializeComponent();
- }
- private void FormPrincipal_Load(object sender, EventArgs e)
- {
- List<Cidadao> cidadaos = new List<Cidadao>();
- string arqTxt = @"C:eclipseteste1.txt";
- if (File.Exists(arqTxt))
- {
- try
- {
- using (StreamReader sr = new StreamReader(arqTxt))
- {
- String linha;
- while((linha = sr.ReadLine()) != null)
- {
- int formNumeroRegistro;
- string formNomeCompleto;
- string formDataNascimento;
- string formEstadoCivil;
- string formProfissao;
- string[] linhaExplodida = linha.Split(';');
- formNumeroRegistro = Convert.ToInt32(linhaExplodida[0]);
- formNomeCompleto = linhaExplodida[1];
- formDataNascimento = linhaExplodida[2];
- formEstadoCivil = linhaExplodida[3];
- formProfissao = linhaExplodida[4];
- Cidadao cidadao = new Cidadao(formNumeroRegistro, formNomeCompleto, formDataNascimento, formEstadoCivil, formProfissao);
- cidadaos.Add(cidadao);
- }
- }
- if (cidadaos.Count > 0)
- {
- Cidadao pessoa1 = this.cidadaos[0];
- textNumeroRegistro = pessoa1.profissao;
- }
- } catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- } else
- {
- MessageBox.Show("Arquivo " + arqTxt + " não localizado");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment