Implicit/Explicit conversion between two lists/IEnumerable in c# [duplicate] - c#

This question already has answers here:
Convert List<DerivedClass> to List<BaseClass>
(13 answers)
C# adding implict conversions to existing types
(2 answers)
Closed 2 years ago.
Can I make Implicit/Explicit conversion between two lists i.e.
List<Person> person = new List<Human>();

Related

C# Check if a method exists in TDD [duplicate]

This question already has answers here:
How to check whether an object has certain method/property?
(5 answers)
Reflection GetMethod. select a more specific method
(3 answers)
Closed 11 months ago.
In Java I can check if a method named "addNumbers" exists in a class "Calculate" by doing this:
Class<?> c = Class.forName("com.example.package.Calculate");
Method m = c.getMethod("addNumbers", int.class, int.class);
m.invoke(5,7)
What is the C# equivalent for this example?

C# Generics, what does T<,> mean? [duplicate]

This question already has answers here:
Generics open and closed constructed types
(3 answers)
C# Language: generics, open/closed, bound/unbound, constructed
(2 answers)
Closed 3 years ago.
I have not seen this <,>-syntax before, and its impossible to google.
cfg.For(typeof(IPipelineBehavior<,>)).Add(typeof(OuterBehavior<,>));
.. I m guessing its some kind of wildcard, but I cant find any documentation
Source (for example)

Why do Arrays implement generic collections at run time? [duplicate]

This question already has answers here:
Why isn't Array a generic type?
(7 answers)
How do arrays in C# partially implement IList<T>?
(6 answers)
Relation between IEnumerable and arrays
(3 answers)
Closed 3 years ago.
In the documentation it says:
Single-dimensional arrays implement the
System.Collections.Generic.IList<T>,
System.Collections.Generic.ICollection<T>,
System.Collections.Generic.IEnumerable<T>,
System.Collections.Generic.IReadOnlyList<T> and
System.Collections.Generic.IReadOnlyCollection<T> generic interfaces.
The implementations are provided to arrays at run time.
Why are the provided at run-time, and not in the Array class definition?

Overloading an addition operator for a List using generic types [duplicate]

This question already has answers here:
Can I overload an == operator on an Interface?
(5 answers)
Operator Overloading with C# Extension Methods
(7 answers)
Closed 5 years ago.
I tried to code something like this:
public static List<T> operator+<T>(List<T> list1, List<T> list2)
{
return list1.Concat(list2).ToList();
}
It didn't work.
None of the questions I could find about "operator overloading with generics" were about extension methods. This question is not a duplicate because the other question doesn't mention generic types.

How to declare an Optional type in C#? [duplicate]

This question already has answers here:
Optional return in C#.Net
(13 answers)
Closed 8 years ago.
Java 8 has Optional<T> which is nice way to declare optional types as described here.
Is there an equivalent way to that in C# ?
As per this answer You could make a struct that mimics this this type of functionality.

Categories