Click here to Skip to main content
16,021,997 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionScrape with htmlagilitypack problems Pin
Member 175325016-Dec-19 6:02
Member 175325016-Dec-19 6:02 
AnswerRe: Scrape with htmlagilitypack problems Pin
Richard Deeming16-Dec-19 8:41
mveRichard Deeming16-Dec-19 8:41 
GeneralRe: Scrape with htmlagilitypack problems Pin
Member 175325018-Dec-19 11:22
Member 175325018-Dec-19 11:22 
QuestionASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol15-Dec-19 9:33
Mou_kol15-Dec-19 9:33 
AnswerRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming16-Dec-19 8:30
mveRichard Deeming16-Dec-19 8:30 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Mou_kol24-Dec-19 21:14
Mou_kol24-Dec-19 21:14 
GeneralRe: ASP.Net MVC: How data is serialize into model when pass to client side from action Pin
Richard Deeming7-Jan-20 8:09
mveRichard Deeming7-Jan-20 8:09 
QuestionHow do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 21:39
Marc Hede12-Dec-19 21:39 
I have finally gotten my code to work, but there is one thing left that I want to do.
In my code I had made a Keycard class that had a name and a keynumber.
What I would like to do is to change the Keycard class to Person Class, which keeps the Name string, and then add the Keycard class as a child to the Person class, which keeps the Mykey int.

I have done inheritance before, but I have not tried doing it in a file that also uses Serialization.
How should the code look?

Also, a small bonus question. As you can see, my code gives a binary output. Like with XML, is there a way to show this binary output on a web application?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace Keycard
{
    [Serializable()]
    public class Keycard : ISerializable
    {
        protected string name;
        protected int mykey;

        public Keycard(string name, int mykey)
        {
            this.Name = name;
            this.Mykey = mykey;
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public int Mykey
        {
            get { return mykey; }
            set { mykey = value; }
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {

            info.AddValue("Name", name);
            info.AddValue("Keynumber", mykey);

        }
        public Keycard(SerializationInfo info, StreamingContext context)
        {
            Name = (string)info.GetValue("Name", typeof(string));
            Mykey = (int)info.GetValue("Keynumber", typeof(int));
        }

        public override string ToString()
        {
            return "Name: " + name + " ---- " + " Keynumber: " + mykey;
        }
    }
}


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

namespace Keycard
{
    class Class1
    {
        public static void Main(string[] args)
        {
            Keycard d1 = new Keycard("John", 102030);

            Stream stream = File.Open("KeycardData.dat",
                FileMode.Create);

            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(stream, d1);
            stream.Close();

            d1 = null;

            stream = File.Open("KeycardData.dat", FileMode.Open);

            bf = new BinaryFormatter();

            d1 = (Keycard)bf.Deserialize(stream);
            stream.Close();
            Console.WriteLine(d1.ToString());
            Console.ReadLine();

        }
    }
}

AnswerRe: How do I change this code using Inheritance? Pin
Richard MacCutchan12-Dec-19 22:15
mveRichard MacCutchan12-Dec-19 22:15 
AnswerRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 22:23
professionalphil.o12-Dec-19 22:23 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 22:57
Marc Hede12-Dec-19 22:57 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o12-Dec-19 23:26
professionalphil.o12-Dec-19 23:26 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede12-Dec-19 23:49
Marc Hede12-Dec-19 23:49 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore12-Dec-19 23:59
professionalF-ES Sitecore12-Dec-19 23:59 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:17
Marc Hede13-Dec-19 0:17 
GeneralRe: How do I change this code using Inheritance? Pin
phil.o13-Dec-19 0:52
professionalphil.o13-Dec-19 0:52 
GeneralRe: How do I change this code using Inheritance? Pin
F-ES Sitecore13-Dec-19 0:54
professionalF-ES Sitecore13-Dec-19 0:54 
GeneralRe: How do I change this code using Inheritance? Pin
Richard Deeming13-Dec-19 0:58
mveRichard Deeming13-Dec-19 0:58 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:00
mveRichard MacCutchan13-Dec-19 0:00 
GeneralRe: How do I change this code using Inheritance? Pin
Marc Hede13-Dec-19 0:25
Marc Hede13-Dec-19 0:25 
GeneralRe: How do I change this code using Inheritance? Pin
Richard MacCutchan13-Dec-19 0:44
mveRichard MacCutchan13-Dec-19 0:44 
QuestionHistogram in Asp.net using canvas js Pin
pooja thombare11-Dec-19 20:47
pooja thombare11-Dec-19 20:47 
AnswerRe: Histogram in Asp.net using canvas js Pin
Richard MacCutchan11-Dec-19 21:16
mveRichard MacCutchan11-Dec-19 21:16 
JokeRe: Histogram in Asp.net using canvas js Pin
Richard Deeming12-Dec-19 12:54
mveRichard Deeming12-Dec-19 12:54 
AnswerRe: Histogram in Asp.net using canvas js Pin
phil.o11-Dec-19 23:05
professionalphil.o11-Dec-19 23:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.