elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  serializar y deserializar en c#
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: serializar y deserializar en c#  (Leído 2,298 veces)
sebapoli00

Desconectado Desconectado

Mensajes: 20


Ver Perfil
serializar y deserializar en c#
« en: 18 Septiembre 2019, 03:09 am »

buenas, llevo horas dandole vueltas a un asunto que no he logrado solucionar.

lo que quiero hacer es serializar una lista de Account (cuentas) al momento de cerrar el programa y deserializarlo cuando lo vuelva a iniciar para tener las Account que ya fueron registradas.

mi clase Account es:
Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ParkingSystem
  8. {
  9.    public class Account
  10.    {
  11.        public int balance { get; set; }
  12.  
  13.        public string mobile { get; set; }
  14.  
  15.        public Account()
  16.        {
  17.  
  18.        }
  19.  
  20.        public Account(int newBalance, String newMobile)
  21.        {
  22.            balance = newBalance;
  23.            mobile = newMobile;
  24.        }
  25.  
  26.        public void addBalance(int newBalance)
  27.        {
  28.            balance += newBalance;
  29.        }
  30.    }
  31. }
  32.  

clase con la lista:

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Serialization;
  8.  
  9. namespace ParkingSystem
  10. {
  11.    public class SystemController
  12.    {
  13.        private static List<Account> accountsList = new List<Account>();
  14.  
  15.        public void addAccount(Account account)
  16.        {
  17.            accountsList.Add(account);
  18.        }
  19.  
  20.        public List<Account> GetAccounts()
  21.        {
  22.            return accountsList;
  23.        }
  24.    }
  25. }
  26.  

como podria serializar y deserializar de manera sencilla?

Muchas gracias.


En línea

ThunderCls


Desconectado Desconectado

Mensajes: 455


Coder | Reverser | Gamer


Ver Perfil WWW
Re: serializar y deserializar en c#
« Respuesta #1 en: 16 Octubre 2019, 17:53 pm »

La forma mas sencilla es usando el atributo de clase [Serializable]

https://docs.microsoft.com/en-us/dotnet/api/system.serializableattribute?view=netframework-4.8
https://www.c-sharpcorner.com/article/serialization-and-deserialization-in-c-sharp/


En línea

-[ "…I can only show you the door. You're the one that has to walk through it." – Morpheus (The Matrix) ]-
http://reversec0de.wordpress.com
https://github.com/ThunderCls/
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
[C#] Deserializar JSON
.NET (C#, VB.NET, ASP)
Siuto 1 4,811 Último mensaje 9 Septiembre 2010, 17:55 pm
por [D4N93R]
Problema Serializar/Deserializar
.NET (C#, VB.NET, ASP)
Maurice_Lupin 2 3,430 Último mensaje 23 Noviembre 2011, 16:17 pm
por Maurice_Lupin
Como serializar en c++? (dev c++)
Programación C/C++
fabian7593 3 5,019 Último mensaje 25 Septiembre 2013, 08:33 am
por eferion
Serializar ConcurrentMap
Java
mapers 1 1,458 Último mensaje 28 Febrero 2014, 17:21 pm
por 1mpuls0
Deserializar una cookie
Hacking
THEGAME008 2 2,248 Último mensaje 17 Febrero 2022, 11:59 am
por MCKSys Argentina
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines