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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:55:38+00:00 2026-05-11T12:55:38+00:00

(Thanks everyone for the answers, here is my refactored example , in turn another

  • 0

(Thanks everyone for the answers, here is my refactored example, in turn another StackOverflow question about the Single Responsibility Principle.)

Coming from PHP to C#, this syntax was intimidating:

container.RegisterType<Customer>('customer1'); 

until I realized it expresses the same thing as:

container.RegisterType(typeof(Customer), 'customer1'); 

as I demonstrate in the code below.

So is there some reason why generics is used here (e.g. throughout Unity and most C# IoC containers) other than it just being a cleaner syntax, i.e. you don’t need the typeof() when sending the type?

using System;  namespace TestGenericParameter {     class Program     {         static void Main(string[] args)         {             Container container = new Container();             container.RegisterType<Customer>('test');             container.RegisterType(typeof(Customer), 'test');              Console.ReadLine();         }     }      public class Container     {         public void RegisterType<T>(string dummy)         {             Console.WriteLine('Type={0}, dummy={1}, name of class={2}', typeof(T), dummy, typeof(T).Name);         }          public void RegisterType(Type T, string dummy)         {             Console.WriteLine('Type={0}, dummy={1}, name of class={2}', T, dummy, T.Name);         }      }      public class Customer {} }  //OUTPUT: //Type=TestGenericParameter.Customer, dummy=test, name of class=Customer //Type=TestGenericParameter.Customer, dummy=test, name of class=Customer 
  • 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-11T12:55:39+00:00Added an answer on May 11, 2026 at 12:55 pm

    A primary reason is the type safety at compile time. If you are passing two Type objects you are placing the responsibility at the developer instead of the compiler.

    This is also why many IoC containers utilizes it, as your compiler will complain if an concrete type isn’t inheriting the abstract type.

    public void Register<TAbstract, TConcrete>() where TConcrete : TAbstract { } 

    This code will only work if TConcrete is implementing or inheriting TAbstract. If this method took two Type parameters, your method should validate this relationship.

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

Sidebar

Related Questions

Thanks everybody. (For some reason I couldn't up vote answers, so everyone wins today
Update : I have a couple of what are probably silly questions about commenter
Here's my setup: I am passing two arrays as XML into a SQL stored
I am looking for a way to modify catch block depending on if it's
I am working on different technologies and frameworks. I write: web applications using GWT,
I want to add objects of a custom type to a Set. I have
I am stuck on the last few problems of an array exercise. Could anyone
I need some ideas how to handle the database structure for a site i'm
I am seeing a strange issue when fetching a JSON object from a URL
I am following Phil Haacks tutorial on using JQGrid with ASP.Net MVC. My 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.