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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:08:28+00:00 2026-05-10T16:08:28+00:00

In Java, one can declare a variable parameterised by an unknown generic type, which

  • 0

In Java, one can declare a variable parameterised by an ‘unknown’ generic type, which looks like this:

Foo<?> x; 

Is there an equivalent construct to this question-mark, in C#?

  • 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-10T16:08:28+00:00Added an answer on May 10, 2026 at 4:08 pm

    The short answer is no. There isn’t an equivalent feature in C#.

    A workaround, from C# from a Java developer’s perspective by Dare Obasanjo:

    In certain cases, one may need create a method that can operate on data structures containing any type as opposed to those that contain a specific type (e.g. a method to print all the objects in a data structure) while still taking advantage of the benefits of strong typing in generics. The mechanism for specifying this in C# is via a feature called generic type inferencing while in Java this is done using wildcard types. The following code samples show how both approaches lead to the same result.

    C# Code

    using System; using System.Collections; using System.Collections.Generic;   class Test{      //Prints the contents of any generic Stack by      //using generic type inference      public static void PrintStackContents<T>(Stack<T> s){         while(s.Count != 0){             Console.WriteLine(s.Pop());          }      }      public static void Main(String[] args){      Stack<int> s2 = new Stack<int>();      s2.Push(4);      s2.Push(5);      s2.Push(6);       PrintStackContents(s2);           Stack<string> s1 = new Stack<string>();      s1.Push('One');      s1.Push('Two');      s1.Push('Three');       PrintStackContents(s1);      } } 

    Java Code

    import java.util.*;   class Test{      //Prints the contents of any generic Stack by      //specifying wildcard type      public static void PrintStackContents(Stack<?> s){         while(!s.empty()){             System.out.println(s.pop());          }     }      public static void main(String[] args){      Stack <Integer> s2 = new Stack <Integer>();      s2.push(4);      s2.push(5);      s2.push(6);       PrintStackContents(s2);           Stack<String> s1 = new Stack<String>();      s1.push('One');      s1.push('Two');      s1.push('Three');         PrintStackContents(s1);      } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 113k
  • Answers 113k
  • 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 you don't need parens around the second SELECT statement... Also,… May 11, 2026 at 10:08 pm
  • Editorial Team
    Editorial Team added an answer You could also nest tables: <table> <tr><td><!----- row 1 -->… May 11, 2026 at 10:08 pm
  • Editorial Team
    Editorial Team added an answer Rather than using the String.replace method, I'd suggest using the… May 11, 2026 at 10:08 pm

Related Questions

The following method does not work because the inner block declares a variable of
If you had to choose your Favorite (clever) techniques for defensive coding, what would
C# has syntax for declaring and using properties. For example, one can declare a
In many past projects, I used this JPA / Hibernate approach to add auditing

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.