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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:44:18+00:00 2026-05-27T13:44:18+00:00

I am trying to understand generics. Here’s an example of one: public static bool

  • 0

I am trying to understand generics. Here’s an example of one:

   public static bool CreateTableIfNotExist<T>(this CloudTableClient tableStorage, string entityName)
        where T : TableServiceEntity, new()
    {
        bool result = tableStorage.CreateTableIfNotExist(entityName);

        return result;
    }

I have a couple of questions. Firstly, what’s the purpose of new() in the definition. My other question is, how can I use this generic. There’s an example here:

_tableStorage.CreateTableIfNotExist<MembershipRow>(_tableName);

But i don’t understand. What really is the purpose of this generic? Can’t I just do the same thing without the generic?

_tableStorage.CreateTableIfNotExist("MyNewTable");
  • 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-27T13:44:18+00:00Added an answer on May 27, 2026 at 1:44 pm

    It is a generic type constraint stating that the type must have a public parameterless constructor.

    myCloudTableClient.CreateTableIfNotExist<TypeWithPublicParameterlessConstructor>("Customers");
    

    Further reading.

    The main use of this is to allow the generic code to construct an instance of T, as opposed to default(T) – something you may often see. Unfortunately, there is no constraint support for anything other than a public parameterless constructor, when it comes to constraining on constructors.

    Update: looking at the code you have updated, the generic isn’t ever used so in this case it has no purpose. A common tactic for generics on extension methods is to support generic extension methods.

    public static bool Equals<T>(this T self, T other) where T : IEquatable<T>
    {
        return self.Equals(other);
    }
    

    Update 2: in your example of not specifying the type constraint, this would only work if the type constraint could be inferred by the compiler based on usage… I’m not sure what would happen in your case, but I’d guess it wouldn’t compile.

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

Sidebar

Related Questions

I am trying to understand what is IAsyncresult good and therefore I wrote this
here are some generic tables, I am trying to fully understand how to properly
I am going through a book trying to understand Generics with C# and I
I'm a C# guy learning Java and I'm trying to understand how generics work
This is more of a generic question. But I am trying to understand a
I'm trying to understand how this login page works by looking at the source
I'm doing some experiments, trying to understand the issues surrounding returning generics. The following
I'm working through the Erlang documentation, trying to understand the basics of setting up
I am trying to determine if it is possible to use Generics in the
As explained, for example, here , there are 3 main uses for the void

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.