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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:16:54+00:00 2026-05-10T19:16:54+00:00

I have a class that contains two methods like these: public String getFoo(Int32 a)

  • 0

I have a class that contains two methods like these:

public String getFoo(Int32 a) {   return getBar(a, 'b', null); }  public String getBar(Int32 a, String b, Int32 c) {   //do something   return ''; } 

However when I compile my class I get two errors:

  1. The best overloaded method match for getBar(int,string,int) has some invalid arguments
  2. Argument ‘3’: cannot convert from ‘<null>‘ to ‘int’

I think I understand why I’m getting this error: the compiler doesn’t know at the time of compilation what the real type of the object is. Can someone confirm if I’m correct about the cause of the error or point out the real reason?

More importantly, can I design my code this way? If so, what do I need to do to fix the errors? My reason for designing my class this way is because I don’t want to duplicate the code in getBar, in getFoo. The two methods do essentially the same thing except one takes a third parameter.

Thanks.

  • 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. 2026-05-10T19:16:54+00:00Added an answer on May 10, 2026 at 7:16 pm

    In .NET, there is a distinct concept between reference types and value types.

    A reference type is an object that is allocated on the heap (It will be a subclass of System.Object). All that is on the stack is a pointer to this object. Because of that, it is perfectly valid to store a null pointer.

    A value type is an object that is allocated on the stack, it will be a subclass of System.ValueType. Because a value type lives on the stack, when you pass its value to a function, you pass the entire contents of the object.

    Value types cannot be null.

    Most C# primitive types are value types. String is a special type of primitive that is actually a reference type.

    In .NET 2.0, MS added the ability to enclose a generic type inside of a struct so that it could simulate a nullable type. What really happens is that the logic inside of the Nullable<T> struct is emulating a null for you.

    They expressed it using a syntax shortcut by adding a question mark to the type, for example:

    int? nullableInt = null; float? nullableFloat = null; 

    etc…

    If you don’t like the int? syntax, you can always use Nullable<SomeType>

    public String getBar(Int32 a, String b, Nullable<Int32> c) 

    As a side note, I prefer to add an overload when doing what you are doing, just to make the syntax nicer.

    public String getBar(Int32 a, String b) {      this.getBar(a,b,null); }  public String getBar(Int32 a, String b, Nullable<Int32> c) { } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 174k
  • Answers 174k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to make the assembly's friends with the InternalsVisibleTo… May 12, 2026 at 2:54 pm
  • Editorial Team
    Editorial Team added an answer Though rare for me, I sometimes feel that writing in… May 12, 2026 at 2:54 pm
  • Editorial Team
    Editorial Team added an answer Well, if the access side seems to be freezing, consider… May 12, 2026 at 2:54 pm

Related Questions

Lets say you have various objects of arbitrary type that you would like to
I am currently trying to tackle a speed issue involving loading and saving richtext.
As I mention in an earlier question, I'm refactoring a project I'm working on.
When implementing IDisposable correctly, most implementations, including the framework guidelines, suggest including a private

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.