473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How do i go about Serailizing A List

I Have A List (Fleet) Which Stores Instances of A Class (Transport) which is more specifficly (Car ,Minibus ,Truck)

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Runtime.Serialization;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. using System.IO;
  9.  
  10. namespace SD2coursework
  11. {
  12.     [Serializable()]
  13.     public class Fleet
  14.     {
  15.         /*
  16.          * This class is used to hold a list of Car objects that make up the fleet:
  17.          * The car objects may be added through the addToFleet() method.
  18.          * The car objects may be deleted tgrough the deleteFromFleet() method 
  19.          * Use the fleet property to access the list of car objects
  20.          */ 
  21.  
  22.         public List<Transport> theFleet = new List<Transport>(); //The list of car objects being stored
  23.         public List<Transport> fleet 
  24.             /* The fleet property. Note that you can only read it
  25.              * use the addToFleet and deleteFromFleet to update it
  26.              */
  27.         {
  28.             get
  29.             {
  30.                 return theFleet;
  31.             }
  32.         }
  33.  
  34.         public void deleteFromFleet(Transport a)
  35.             //Delete car from fleet
  36.         {
  37.             theFleet.Remove(a);
  38.         }
  39.  
  40.         public void addToFleet(Transport a)
  41.             //Add car to fleet
  42.         {
  43.             theFleet.Add(a);
  44.         }
  45.  
  46.     }
  47. }
  48.  
The Problems Occuring are , whilst attempting to use XML i have no parameterless contructor, and using binary it cannot explictly change Fleet to Transport
Nov 26 '10 #1
1 1003
GaryTexmo
1,501 Expert 1GB
The reason you need a parameterless constructor is because when the object is being created, the framework calls the parameterless constructor and then calls various properties to set the information.

Have a look here:

http://www.agiledeveloper.com/articl...ialization.pdf

I've found that link to be extremely valuable when trying to get XML Serialization working. There's also a section at the end for how to work with collection objects.
Nov 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: massimo | last post by:
Hey, I wrote this program which should take the numbers entered and sort them out. It doesnąt matter what order, if decreasing or increasing. I guess I'm confused in the sorting part. Anyone...
10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
24
by: Robin Cole | last post by:
I'd like a code review if anyone has the time. The code implements a basic skip list library for generic use. I use the following header for debug macros: /* public.h - Public declarations and...
4
by: JS | last post by:
I have a file called test.c. There I create a pointer to a pcb struct: struct pcb {   void *(*start_routine) (void *);   void *arg;   jmp_buf state;   int    stack; }; ...
3
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h>...
0
by: drewy2k12 | last post by:
Heres the story, I have to create a doubly linked list for class, and i have no clue on how to do it, i can barely create a single linked list. It has to have both a head and a tail pointer, and...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
12
by: kalyan | last post by:
Hi, I am using Linux + SysV Shared memory (sorry, but my question is all about offset + pointers and not about linux/IPC) and hence use offset's instead on pointers to store the linked list in...
0
by: saijin | last post by:
I'm planning to call a list of data from an XML file but when I duplicate the content inside the <data></data> it is not showing anything Here's the ActionScript 3.0 import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.