Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6185019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:38:23+00:00 2026-05-24T01:38:23+00:00

This is my code so far: using System; using System.Collections; using System.Linq; using System.Text;

  • 0

This is my code so far:

using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Xml;

namespace Opgaver
{
     class OpgaveController
    {
        static ArrayList _arrAktiveOpgaver = new ArrayList();
        public ArrayList arrAktiveOpgaver
        {
            get { return _arrAktiveOpgaver; }
            set { _arrAktiveOpgaver = value; }
        }

        static ArrayList _arrAfsluttedeOpgaver = new ArrayList();
        public ArrayList arrAfsluttedeOpgaver
        {
            get { return _arrAfsluttedeOpgaver; }
            set { _arrAfsluttedeOpgaver = value; }
        }

        static int _opgavenr = 100;
        public int opgavenr
        {
            get { return _opgavenr; }
            set { _opgavenr = value; }
        }

        public void opretOpgave(string opgavenavn, string opgavebeskrivelse, int opgaveprioritet, DateTime opgaveafsluttetdato)
        {
            DateTime oprettetdato = new DateTime();
            oprettetdato = DateTime.Now;
            bool opgaveafsluttet = false;
            Opgave opgave = new Opgave(oprettetdato, _opgavenr, opgavenavn, opgavebeskrivelse, opgaveprioritet, opgaveafsluttet, opgaveafsluttetdato);

            if (opgave.opgaveAfsluttet == false)
            {
                _arrAktiveOpgaver.Add(opgave);
            }
            else
            {
                _arrAfsluttedeOpgaver.Add(opgave);
            }

            _opgavenr++;
        }

        public OpgaveController()
        {

        }



        }

        public void test()
        { 
            string outfile = @"C:\Folder\Tester.xml";

            XmlSerializer xs;

            Serialize<List<Opgave>>(arrAktiveOpgaver, outfile);
            arrAktiveOpgaver = <List<Opgave>>(outfile);//deserialize data - Generates this error: Error 2   Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments   P:\Programmerings opgaver\Opgaver\Opgaver\OpgaveController.cs   107 33  Opgaver

        }

        private void Serialize<T1>(ArrayList arrAktiveOpgaver, string outfile)
        {
            throw new NotImplementedException();
        }

        public static T DeserializeFromXml<T>(string inputFile)
        {
            XmlSerializer s = new XmlSerializer(typeof(T));
            T deserializedObject = default(T);

            using (TextReader textReader = new StreamReader(inputFile))
            {
                deserializedObject = (T)s.Deserialize(textReader);
                textReader.Close();
            }

            return deserializedObject;
        }

        public static void SerializeToXml<T>(T objToSerialize, string outputFile)
        {

            XmlSerializer s = new XmlSerializer(objToSerialize.GetType());

            using (TextWriter textWriter = new StreamWriter(outputFile))
            {
                s.Serialize(textWriter, objToSerialize);
                textWriter.Close();
            }
        }

    }
}

i need to serialize the arraylist, and deserialize it..

and here is my opgave class:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Opgaver
{
    [Serializable()] public class Opgave : IComparable
    {
        DateTime _oprettetDato = new DateTime();
        public DateTime oprettetDato
        {
            get { return _oprettetDato; }
            set { _oprettetDato = value; }
        }

        int _opgavenr;
        public int opgavenr
        {
            get { return _opgavenr; }
            set { _opgavenr = value; }
        }

        string _opgaveNavn;
        public string opgaveNavn
        {
            get { return _opgaveNavn; }
            set { _opgaveNavn = value; }
        }

        string _opgaveBeskrivelse;
        public string opgaveBeskrivelse
        {
            get { return _opgaveBeskrivelse; }
            set { _opgaveBeskrivelse = value; }
        }

        int _opgavePrioritet;
        public int opgavePrioritet
        {
            get { return _opgavePrioritet; }
            set { _opgavePrioritet = value; }
        }

        bool _opgaveAfsluttet = false;
        public bool opgaveAfsluttet
        {
            get { return _opgaveAfsluttet; }
            set { _opgaveAfsluttet = value; }
        }

        DateTime _opgaveAfsluttetDato = new DateTime();
        public DateTime opgaveAfsluttetDato
        {
            get { return _opgaveAfsluttetDato; }
            set { _opgaveAfsluttetDato = value; }
        }

        public Opgave()
        {
        }

        public Opgave(DateTime oprettetdato, int opgavenr, string opgavenavn, string opgavebeskrivelse, int opgaveprioritet, bool opgaveafsluttet, DateTime opgaveafsluttetdato)
        {
            _oprettetDato = oprettetdato;
            _opgavenr = opgavenr;
            _opgaveNavn = opgavenavn;
            _opgaveBeskrivelse = opgavebeskrivelse;
            _opgavePrioritet = opgaveprioritet;
            _opgaveAfsluttet = opgaveafsluttet;
            _opgaveAfsluttetDato = opgaveafsluttetdato;
        }

        //Sorterings metode
        public int CompareTo(object obj)
        {
            Opgave Compare = (Opgave)obj;
            int result = this.opgavenr.CompareTo(Compare.opgavenr);
            if (result == 0)
                result = this.opgavenr.CompareTo(Compare.opgavenr);
            return result;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:38:24+00:00Added an answer on May 24, 2026 at 1:38 am

    Use this static methods whenver you want to serialize or deserialize data:
    example:

    public void test()
    { 
        string outfile = @"C:\Folder\Tester.xml";
    
        SerializeToXml<List<Opgaver>>(arrAktiveOpgaver, outfile);//serialize data
    
        arrAktiveOpgaver = DeserializeFromXml<List<Opgaver>>(outfile);//deserialize data
    }
    
    public static T DeserializeFromXml<T>(string inputFile)
    {
        XmlSerializer s = new XmlSerializer(typeof(T));
        T deserializedObject = default(T);
    
        using (TextReader textReader = new StreamReader(inputFile))
        {
            deserializedObject = (T)s.Deserialize(textReader);
            textReader.Close();
        }
    
        return deserializedObject;
    }
    
    public static void SerializeToXml<T>(T objToSerialize, string outputFile)
    {
    
        XmlSerializer s = new XmlSerializer(objToSerialize.GetType());
    
        using (TextWriter textWriter = new StreamWriter(outputFile))
        {
            s.Serialize(textWriter, objToSerialize);
            textWriter.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the following code to create a DLL : using System; using System.Collections.Generic;
I have this code so far which perfectly but relies on there being a
As far as I can tell, this code is fine, and should display some
This is what I have as far as code, it is in the first
I am using Excel 2007. I have C# code written in a separate binary.
I have an arraylist<string> of words. I sort it using Collections.sort(wordsList); I'm using this
I'm using this code to make my Java program open a (visible) CMD window:
This code in JS gives me a popup saying i think null is a
This code is from Prototype.js . I've looked at probably 20 different tutorials, and
this code always returns 0 in PHP 5.2.5 for microseconds: <?php $dt = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.