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 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer <input type="checkbox" onclick="toggleValue(this)"> and in handler check the value and… May 11, 2026 at 7:57 pm
  • Editorial Team
    Editorial Team added an answer Read these posts by Mark Russinovich: http://blogs.technet.com/markrussinovich/archive/2008/07/21/3092070.aspx http://blogs.technet.com/markrussinovich/archive/2008/11/17/3155406.aspx May 11, 2026 at 7:57 pm
  • Editorial Team
    Editorial Team added an answer Microsoft published a knowledge base article with a number of… May 11, 2026 at 7:57 pm

Related Questions

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
I have a class that encapsulates tcp socket communications with a server. For each
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've

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.