While providing the same generic type several times for a generic class, it occurred to me, what if there was a default generic type in C#? It would save the hassle of providing the same type. At the same, it would provide the flexibility to use another type. This can improve the productivity of the developer/code reviewer, maintaining flexibility.
I have provided that idea on the GitHub. It is as follows:
Problem:
A generic class can have the same generic type used multiple times. Allow setting default generic type to reduce redundant code and making it easier to read.
A generic class can have the same generic type used multiple times. Allow setting default generic type to reduce redundant code and making it easier to read.
Current:
public class Node<T> { public T Data { get; set; } }
Use:
Node<int> node1 = new Node<int>() { Data = 1}; Node<int> node2 = new Node<int>() { Data = 2}; Node<string> nodeStr = new Node<string>() { Data = "test" };
Proposed: note: T = int in the declaration
public class Node<T = int> { public T Data { get; set; } }
Use:
Node<> node1 = new Node<>() { Data = 1}; Node<> node2 = new Node<>() { Data = 2}; Node<string> nodeStr = new Node<string>() { Data = "test" };
Please provide feedback on the GitHub
Alternatively, you can provide feedback here. I invite you to discuss it.