How do I create a C# interface for T where T extends IComparable<T> and the interface extends IEnumerable<T>

What is the C# equivalent to the following java construct: interface LinkedList<T extends Comparable<T>> extends Iterable<T> I cannot do this the following way in C# because it is assumed that IEnumerable<T>belongs to the the where constraint: interface LinkedList<T> where T : IComparable<T>, IEnumerable <T> how can I do this in C# ? >Solution : I… Read More How do I create a C# interface for T where T extends IComparable<T> and the interface extends IEnumerable<T>

Collection initializer for wrapper class and avoiding boxing of IEnumerator<T>

I have a wrapper struct for a Dictionary and I want to add a collection initializer to this class that adds my entries to the wrapped Dictionary. public readonly struct Wrapper : IEnumerable<KeyValuePair<string, string>> { public Dictionary<string, string> Instance { get; } public Wrapper() { Instance = new Dictionary<string, string>(); } public void Add(string key,… Read More Collection initializer for wrapper class and avoiding boxing of IEnumerator<T>

Cast IEnumerable<T> to List<T> after IEnumerable<> being returned in async function

How to convert IEnumerable<T> to List<T> after getting IEnumerable<T> from async function? My code: var orders = await _DbManager.Orders.GetAllAsync(); _DbManager.Orders.GetAllAsync() returns IEnumerable<Orders> and i want to avoid multiple-enumeration but _DbManager.Orders.GetAllAsync().ToList() gives me that error: Task<IEnumerable<Orders>> does not contain a definition for ToList…. What is the best solution to deal with this problem? >Solution : Try… Read More Cast IEnumerable<T> to List<T> after IEnumerable<> being returned in async function

How to handle "The given header was not found" when paging records in c# API GET request?

I’m requesting data from an API that requires paging records based on a custom header called "cursor". Only 100 records may be retrieved per call and as such I’ve created a while loop to execute. The loop functions… until it doesn’t. Once all records are paged, the headers get dropped and my program errors out… Read More How to handle "The given header was not found" when paging records in c# API GET request?

How should I resolve ASP.NET Core multiple endpoints error

My controller is: [Route("api/[controller]")] [ApiController] public class SubjectController : ControllerBase { private TourActivityExpenseContext tourActivityExpenseContext = new TourActivityExpenseContext(); [HttpGet] public IEnumerable<SubjectTo> Get() { var subjects = tourActivityExpenseContext.SubjectTos.ToList(); return subjects; } [HttpGet("{subject}")] public int GetSubjectId(String subject) { var subjects = tourActivityExpenseContext.SubjectTos.ToList(); var isSub = subjects.FirstOrDefault(x => x.Subject == subject); int id = isSub.Id; return id; } [HttpGet("{id}")]… Read More How should I resolve ASP.NET Core multiple endpoints error