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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:07:42+00:00 2026-06-13T23:07:42+00:00

Possible Duplicate: C# Implicit/Explicit Type Conversion I have an int that I am attempting

  • 0

Possible Duplicate:
C# Implicit/Explicit Type Conversion

I have an int that I am attempting to box, so as to use it in a constructor which takes as a parameter object of CustomType.

An example of what I mean.

 int x = 5;
 object a = x;

 CustomType test = new CustomType(a)

 //constructor in question
 public CustomType(CustomType a)
 {
   //set some variables etc
 }

Howver I get the following error

 The best overloaded method match for X has some invalid arguments.

So obviously I’m way off the mark. Where am I going wrong? Is boxing the right solution or should i be looking at type casting?

  • 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-13T23:07:43+00:00Added an answer on June 13, 2026 at 11:07 pm

    That constructor takes a CustomType type as a parameter; you’re passing it an int. An int is not a CustomType, and the C# language knows of no implicit conversions from int to CustomType. That’s why you’re getting an error.

    Casting the int to an object doesn’t change the fact that it’s still not a CustomType.

    Looking at that particular constructor, it’s a copy constructor. It takes a type of itself as a parameter. There is (one would hope) another constructor that takes another parameter, whether that’s an int, or some other type that you haven’t mentioned, or possibly no parameters and you need to just set a property after creating a default object.

    As for actual solutions, there are many. Here are a few:

    1. Add an additional constructor to CustomType that accepts an int.
    2. Define a function that takes an int as a parameter and returns a CustomObject; this would be a “conversion” function that you could use.
    3. Use a default constructor of CustomType and set a property with your integer (may or may not be applicable, depending on what CustomType does.

    Boxing doesn’t seem to be related to the issue at hand. It’s not something that you should use to pass an integer to a custom type. If you would like to know more about what boxing is, how it works, or when it’s useful then consider asking a question that addresses those points because this particular problem would be harmed by using boxing as a solution, not helped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Explicit vs implicit SQL joins I have two queries in SQL Server.
Possible Duplicate: Type result with conditional operator in C# Basically I have some code
Possible Duplicate: Is there a way to define an implicit conversion operator in VB.NET?
Possible Duplicate: Why does ReSharper want to use 'var' for everything? I have ReSharper
Possible Duplicate: Explicit vs implicit SQL joins Stmt1: SELECT ... FROM ((a JOIN b
Possible Duplicate: C#: Interfaces - Implicit and Explicit implementation Would someone explain the differences
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Explicit vs implicit SQL joins Is there a difference using join andselect
Possible Duplicate: behaviour of the implicit copy constructor / assignment operator C++ - conditions
Possible Duplicate: Can’t create handler inside thread that has not called Looper.prepare() inside AsyncTask

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.