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

  • Home
  • SEARCH
  • 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 8899653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:54:36+00:00 2026-06-15T00:54:36+00:00

I’m creating a simple application that takes a URL and a String and create

  • 0

I’m creating a simple application that takes a URL and a String and create the code for a hyperlink.

Here is my HyperLink Class

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

 namespace LinkIt_
{
class HyperLink
{
    private string url;
    private string text;

    public HyperLink()
    {

    }

    public HyperLink(string url,string text)
    {
        this.Website = url;
        this.Text = text;
    }


    public String Website
    {
        get
        {
            return url;
        }
        set
        {
            if (String.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("Must have URL!");
            }

            this.url = value;
        }


    }

    public String Text
    {

        get
        {
            return text;
        }

        set
        {
            if (String.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException("Must have Text!");
            }
            this.text = value;
        }



    }

    public string addPoint()
    {

        return String.Format("<li><a href=" + "\" {0} \">", url) + text + "</a></li>";  
    }

    public override string ToString()
    {

        return String.Format("<a href=" + "\" {0} \">",url) + text + "</a>" ;   
    }



           }
       }

Here is my Form Class

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

 namespace LinkIt_
 {
        public partial class Form1 : Form
{


    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        HyperLink link;
            try
            {

                if (chkPoint.Checked)
                {

                    txtDisplay.Text = "";
                    link = new HyperLink(txtLink.Text, txtText.Text);
                    txtDisplay.Text = link.addPoint();


                }
                else
                {
                    txtDisplay.Text = "";
                    link = new HyperLink(txtLink.Text, txtText.Text);
                    txtDisplay.Text = link.ToString();

                }



            }


            catch (ArgumentNullException msg)
            {
                MessageBox.Show(msg.Message);
            }





   }




    private void btnClear_Click(object sender, EventArgs e)
    {
        txtDisplay.Text = "";
        txtLink.Text = "";
        txtText.Text = "";
    }
}
 }

My Question:

  1. How do I make sure that I don’t create a partially initialized object?

  2. If my code need correcting, Could someone help me ?

  • 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-06-15T00:54:37+00:00Added an answer on June 15, 2026 at 12:54 am

    You could refactor your code to use properties with decreased accessor visibility.
    This way the HyperLink objects can not be altered from outside the class (this is often a preferable attribute for data structures).

    For example you could do something like this:

    class HyperLink
    {
        public String Website{get; private set;}
    
        public String Text {get; private set;}
    
        public HyperLink(string url,string text)
        {
            if(string.isNullOrEmpty(url) || string.IsNullOrEmpty(text))
              throw new ArgumentNullException("no partially intialized object allowed");
    
            this.Website = url;
            this.Text = text;
        }
    
        public string AddPoint()
        {
            return String.Format("<li><a href=" + "\" {0} \">", url) + text + "</a></li>";  
        }
    
        public override string ToString()
        {
            return String.Format("<a href=" + "\" {0} \">",url) + text + "</a>" ;   
        }
    }
    

    Update to answer question in comments

    Yes, it is perfectly reasonable to use the Getter/Setter from within the same object or class.
    However, I advise to improve your usage of String.Format to the following:

    String.Format("<a href=\"{0}\">{1}</a>",this.Link, this.Text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.