Click here to Skip to main content
15,916,835 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Mou_kol8-Apr-19 9:06
Mou_kol8-Apr-19 9:06 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Dave Kreskowiak8-Apr-19 9:24
mveDave Kreskowiak8-Apr-19 9:24 
AnswerRe: C# List: How to do 3 joins for better performance Pin
Mycroft Holmes7-Apr-19 12:17
professionalMycroft Holmes7-Apr-19 12:17 
GeneralRe: C# List: How to do 3 joins for better performance Pin
Mou_kol8-Apr-19 9:09
Mou_kol8-Apr-19 9:09 
QuestionHow to make code run differently depending on the platform it is running on? Pin
Xarzu5-Apr-19 6:44
Xarzu5-Apr-19 6:44 
AnswerRe: How to make code run differently depending on the platform it is running on? Pin
Richard Deeming5-Apr-19 7:15
mveRichard Deeming5-Apr-19 7:15 
AnswerRe: How to make code run differently depending on the platform it is running on? Pin
Gerry Schmitz5-Apr-19 9:54
mveGerry Schmitz5-Apr-19 9:54 
AnswerRe: How to make code run differently depending on the platform it is running on? Pin
jschell7-Apr-19 9:00
jschell7-Apr-19 9:00 
Questionc# Pin
Member 142150015-Apr-19 4:29
Member 142150015-Apr-19 4:29 
AnswerRe: c# Pin
OriginalGriff5-Apr-19 4:39
mveOriginalGriff5-Apr-19 4:39 
QuestionRe: c# Pin
ZurdoDev5-Apr-19 4:49
professionalZurdoDev5-Apr-19 4:49 
AnswerRe: c# Pin
Dave Kreskowiak5-Apr-19 13:03
mveDave Kreskowiak5-Apr-19 13:03 
QuestionHow to convert emoji's unicode strings Pin
Vimalsoft(Pty) Ltd4-Apr-19 20:57
professionalVimalsoft(Pty) Ltd4-Apr-19 20:57 
AnswerRe: How to convert emoji's unicode strings Pin
OriginalGriff4-Apr-19 21:35
mveOriginalGriff4-Apr-19 21:35 
GeneralRe: How to convert emoji's unicode strings Pin
Vimalsoft(Pty) Ltd5-Apr-19 2:13
professionalVimalsoft(Pty) Ltd5-Apr-19 2:13 
QuestionHow do I set a breakpoint in an attached process in visual studio? Pin
Xarzu4-Apr-19 8:43
Xarzu4-Apr-19 8:43 
AnswerRe: How do I set a breakpoint in an attached process in visual studio? Pin
ZurdoDev4-Apr-19 9:20
professionalZurdoDev4-Apr-19 9:20 
GeneralRe: How do I set a breakpoint in an attached process in visual studio? Pin
Xarzu5-Apr-19 4:22
Xarzu5-Apr-19 4:22 
AnswerRe: How do I set a breakpoint in an attached process in visual studio? Pin
Dave Kreskowiak4-Apr-19 9:24
mveDave Kreskowiak4-Apr-19 9:24 
GeneralRe: How do I set a breakpoint in an attached process in visual studio? Pin
Xarzu5-Apr-19 4:22
Xarzu5-Apr-19 4:22 
QuestionSimplify usage of a complex generic class for convenience Pin
Failwyn4-Apr-19 5:02
Failwyn4-Apr-19 5:02 
AnswerRe: Simplify usage of a complex generic class for convenience Pin
Gerry Schmitz4-Apr-19 5:10
mveGerry Schmitz4-Apr-19 5:10 
GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff5-Apr-19 21:00
professionalBillWoodruff5-Apr-19 21:00 
AnswerRe: Simplify usage of a complex generic class for convenience Pin
Richard Deeming4-Apr-19 9:28
mveRichard Deeming4-Apr-19 9:28 
Failwyn wrote:
Ultimately, I don't want there to be anything different between the classes other than the ability to use a simplified signature.

The answer depends on what you mean by that statement.

The derived class is the only solution I can see. But the types would not be exactly the same:
C#
MyClass<Guid> a = new MyClass<Guid>();
MyClass<Guid, Guid, Guid, Guid> b = a; // Works
MyClass<Guid> c = b; // Won't compile - needs an explicit cast
And:
C#
MyClass<Guid, Guid, Guid, Guid> a = new MyClass<Guid, Guid, Guid, Guid>();
MyClass<Guid> b = (MyClass<Guid>)a; // Compiles, but fails at runtime
MyClass<Guid> c = a as MyClass<Guid>; // Compiles and runs, but result is null


Within a single file, you could use a using statement to create an alias for the type. But you can't use generic type parameters in the alias, so you'd need a different one for each set of type parameters you wanted to use:
C#
using MyClassGuid = MyClass<Guid, Guid, Guid, Guid>;
...
MyClassGuid a = new MyClassGuid();
You'd also have to repeat the alias in each file where you needed to use it.


If it's constructing the objects you're worried about, then a factory method might help:
C#
public static class MyClass
{
    public static MyClass<T1, T2, T3, T4> Create<T1, T2, T3, T4>(T1 value1, T2 value2, T3 value3, T4 value4)
    {
        return new MyClass<T1, T2, T3, T4>(value1, value2, value3, value4);
    }
    
    public static MyClass<T1, T1, T1, T1> Create<T1>(T1 value)
    {
        return new MyClass<T1, T1, T1, T1>(value, value, value, value);
    }
}
...
MyClass<Guid, Guid, Guid, Guid> a = MyClass.Create(Guid.New());
MyClass<string, int, decimal, DateTime> b = MyClass.Create("Hello", 42, 123.45M, DateTime.Today);




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Simplify usage of a complex generic class for convenience Pin
BillWoodruff5-Apr-19 4:03
professionalBillWoodruff5-Apr-19 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.