© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago
xyrile

Design pattern

So i was stuck in composite coding with c# I just cant get the ouput maybe someone know about this

namespace Coding.Exercise
  {
    public interface IValueContainer
    {
      
    }

    public class SingleValue : IValueContainer
    {
      public int Value;
    }

    public class ManyValues : List<int>, IValueContainer
    {
      
    }

    public static class ExtensionMethods
    {
      public static int Sum(this List<IValueContainer> containers)
      {
        int result = 0;
        foreach (var c in containers)
        foreach (var i in c)
          result += i;
        return result;
      }
    }
  }
namespace Coding.Exercise
  {
    public interface IValueContainer
    {
      
    }

    public class SingleValue : IValueContainer
    {
      public int Value;
    }

    public class ManyValues : List<int>, IValueContainer
    {
      
    }

    public static class ExtensionMethods
    {
      public static int Sum(this List<IValueContainer> containers)
      {
        int result = 0;
        foreach (var c in containers)
        foreach (var i in c)
          result += i;
        return result;
      }
    }
  }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Design Pattern
C#CC# / help
3y ago
✅ Design Pattern Advice
C#CC# / help
3y ago
❔ HeadFirst Design Pattern
C#CC# / help
3y ago
❔ Design pattern Iterator
C#CC# / help
4y ago