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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:52:36+00:00 2026-05-22T01:52:36+00:00

If you must pass a value type to a method, but for some reason,

  • 0

If you must pass a value type to a method, but for some reason, it must be passed as a reference type, is it faster to:

  1. Pass it as an object
  2. Pass is as a ValueType
  3. Pass it as a generic wrapper

I put some example code below to demonstrate exactly what I mean:.

public class Program
{
    public void Main()
    {
        var client = new IncrementedValueGetter();
        int i = 8675309;
        var byObject = client.IncrementObject(i);
        var byValueType = client.IncrementValueType(i);
        var byWrapper = client.IncrementWrapped(new ValueWrapper<int>(i));
    }
}
public class IncrementedValueGetter
{
    public int IncrementObject(object boxedValue)
    {
        return ((int)boxedValue) + 1;
    }
    public int IncrementValueType(ValueType boxedValueType)
    {
        return ((int) boxedValueType) + 1;
    }
    public int IncrementWrapped(ValueWrapper<int> valueWrapper)
    {
        return valueWrapper.Value + 1;
    }
}
public class ValueWrapper<T> 
    where T: struct
{
    private readonly T _value;
    public ValueWrapper(T value)
    {
        _value = value;
    }

    public T Value
    {
        get { return _value; }
    }
}
  • 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-22T01:52:37+00:00Added an answer on May 22, 2026 at 1:52 am

    The first two are actually equivalent, and just generate the standard box IL. The third one requires the construction of your wrapper class, which is likely more expensive than the box call.

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

Sidebar

Related Questions

I'm using Apache ProxyPass to pass some requests from my server (1) to another
Possible Duplicate: email zend framwork smtp I have following configuration: smtp.type = Zend_Mail_Transport_Smtp smtp.smtpServer
What is wrong with this configuration? I'm using Spring 3 and Hibernate 3.6 and
I have the following urlconf: urlpatterns = patterns('page.manager.views', url(r'^$', 'pages', name='page_manager-pages'), url(r'^add/$', 'add_page', name='page_manager-add_page'),
Great page this one, coming from the perl world and after several years of
I have a function that I want to use to manipulate an input parameter,
From past few days I am trying to find out the location of CGContextRef
I need to do something like this: $('#online-order').wcForms({id: '#online-order', to: 'contact', colors['red']: '#00F' });
EDIT: reworded and simplified question to be consise... In my service layer I have
I need to convert DateTime+TimeZoneInfo into DateTimeOffset. How do I do this? I assume

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.