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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:04:24+00:00 2026-05-15T00:04:24+00:00

In Scala, I can define structural types as follows: type Pressable = { def

  • 0

In Scala, I can define structural types as follows:

type Pressable = { def press(): Unit }

This means that I can define a function or method which takes as an argument something that is Pressable, like this:

def foo(i: Pressable) { // etc.

The object which I pass to this function must have defined for it a method called press() that matches the type signature defined in the type – takes no arguments, returns Unit (Scala’s version of void).

I can even use the structural type inline:

def foo(i: { def press(): Unit }) { // etc.

It basically allows the programmer to have all the benefits of duck typing while still having the benefit of compile-time type checking.

Does C# have something similar? I’ve Googled but can’t find anything, but I’m not familiar with C# in any depth. If there aren’t, are there any plans to add this?

  • 1 1 Answer
  • 2 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-15T00:04:24+00:00Added an answer on May 15, 2026 at 12:04 am

    No, and no plans that I know of. Only named (rather than structural) subtyping (e.g. interfaces).

    (Others may want to see also

    http://en.wikipedia.org/wiki/Nominative_type_system

    http://en.wikipedia.org/wiki/Structural_type_system

    )

    (A few people may point out some exotic corner cases, like the foreach statement using structural typing for GetEnumerator, but this is the exception rather than the rule.)

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

Sidebar

Related Questions

In Scala we can define the type-level identity function for lower-kinded types like so,
In Scala, how can I do something like this: def cast [Type] (x: _
I can define a function that accepts a Seq[Char] def f(s: Seq[Char]) = s
If function accepts structural type, it can be defined as: def doTheThings(duck: { def
As we know that we can define a repeated-parameter (varargs) function in scala, like
As far as I understand, in Scala we can define a function with no
In Scala you can define parameters that descend from other one that take the
In Scala, you can define package objects . It seems thus that you can
Why can't i define a variable recursively in a code block? scala> { |
How can I create an anonymous and curried function in Scala? The following two

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.