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 6079127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:54:40+00:00 2026-05-23T10:54:40+00:00

I try to describe my problem step by step because I do not know

  • 0

I try to describe my problem step by step because I do not know how to say it in correct programming terms.

When I use a System.String type, I do the following:

  1. Declare the type: Dim Str1 as String
  2. Assign its value: Str1 = "This is a string"

I want to create a new type that just like the System.String type but in different name. For example, I want to create a UrlString type for string like this:

  1. Declare the type: Dim Str2 as UrlString
  2. Assign its value: Str2 = "http://www.example.com"

My question is: How do I create the UrlString type?

The reason: I want to create the UrlString type to help me to identify the value of the content. For example, UrlString type means the string is in url format, PhoneString means the string is in phone format, CreditCardString type means the string is in credit card format and so on.

UPDATE:

Thanks Marc Gravell and GSerg. Here is the solution:

Class UrlString
    Private ReadOnly value As String

    Public Sub New(ByVal value As String)
        Me.value = value
    End Sub

    Public Shared Widening Operator CType(ByVal value As String) As UrlString
        Return New UrlString(value)
    End Operator

    Public Shared Widening Operator CType(ByVal u As UrlString) As String
        Return u.value
    End Operator

    Public Overrides Function GetHashCode() As Integer
        Return If(value Is Nothing, 0, value.GetHashCode())
    End Function

    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        Return String.Equals(value, DirectCast(obj, String))
    End Function

    Public Overrides Function ToString() As String
        Return value
    End Function
End Class
  • 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-23T10:54:41+00:00Added an answer on May 23, 2026 at 10:54 am

    You need to add an implicit conversion operator from string to UrlString for that to work. In C#:

    class UrlString
    {
        private readonly string value;
        public UrlString(string value) { this.value = value; }
        public static implicit operator UrlString(string value)
        {
            return new UrlString(value);
        }
        public override int GetHashCode()
        {
            return value == null ? 0 : value.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            return string.Equals(value, (string)obj);
        }
        public override string ToString()
        {
            return value;
        }
    }
    

    Then:

    UrlString foo = "abc";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure if I can describe the problem, but I will try
I really don't know what title should I use to describe my problem. To
This is kind of a oddball problem so I will try to describe the
I dont know how to describe it well, but i will try. Ok, i
Bear with me as I try to describe my problem. I have auto-aligned the
I'm sure my title was hugely unhelpeful, I'll try and describe my problem better
Hello everyone I have a problem I'll try to describe shortly In our application
I have the following problem, will try to describe it shortly. In my program
Hey everybody, Im really confused about this problem. Ill try to describe it: The
This is a difficult problem to describe so please let me know if anything

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.