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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:05:04+00:00 2026-05-11T05:05:04+00:00

I know the default keyword returns the default value of a statically determined type,

  • 0

I know the ‘default’ keyword returns the default value of a statically determined type, as shown for instance in this question.

However, given an instance of a type, is there a simple way to get the default value of this type, dynamically ? The only way I found while googling is this :

static object DefaultValue(Type myType) {     if (!myType.IsValueType)         return null;     else         return Activator.CreateInstance(myType); } 

But I’d like to avoid the Activator class if possible.

  • 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-11T05:05:05+00:00Added an answer on May 11, 2026 at 5:05 am

    This is likely your best route.

    I wouldn’t be afraid of using the Activator class here. This is a pretty standard class that is depended on by the compilers. For instance this VB code

    Public Sub Example(Of T as New)()   Dim x = new T() End Sub 

    Translates into roughly this code

    Public Sub Example(Of T As New)()   Dim x = Activator.CreateInstance(OF T) ENd Sub 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For any given type i want to know its default value. In C#, there
In C# I know you can use the default keyword to assign default values
I know the default Java heap memory is 128 MB. Since it is the
I know the default is ByVal in C#. I used same variable names in
Do you know the default isolation level of the transactions used in Django? Is
Please let me know what are default locations for Downloads folder on devices with
I would like to know if by default is Hashtable passed by reference or
I know I can define default parameters in python, but can I do so
I know mongrel is the default server for script/server but when I do that
I know rails provided CSRF protection by default from rails3. but my web application

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.