Click here to Skip to main content
15,889,863 members
Home / Discussions / C#
   

C#

 
AnswerRe: RegEx help for a RegEx Newb Pin
Christian Graus4-Sep-07 5:11
protectorChristian Graus4-Sep-07 5:11 
GeneralRe: RegEx help for a RegEx Newb Pin
flipdoubt4-Sep-07 5:14
flipdoubt4-Sep-07 5:14 
GeneralRe: RegEx help for a RegEx Newb Pin
Christian Graus4-Sep-07 6:04
protectorChristian Graus4-Sep-07 6:04 
AnswerRe: RegEx help for a RegEx Newb Pin
Joseph Guadagno4-Sep-07 5:14
Joseph Guadagno4-Sep-07 5:14 
GeneralRe: RegEx help for a RegEx Newb Pin
DavidNohejl4-Sep-07 6:03
DavidNohejl4-Sep-07 6:03 
AnswerRe: RegEx help for a RegEx Newb Pin
ednrgc4-Sep-07 5:38
ednrgc4-Sep-07 5:38 
AnswerRe: RegEx help for a RegEx Newb Pin
Skippums4-Sep-07 12:12
Skippums4-Sep-07 12:12 
QuestionC# Generics - Using operators with generic objects Pin
funkymint4-Sep-07 4:28
funkymint4-Sep-07 4:28 
I have the following function:

public bool getOperatorResult<T>(string operatorType, T operandA, T operandB)
        {
            //If the operands are boolean values.
            if (typeof(T) == typeof(bool))
            {
                System.Object obj = operandA;
                bool a = (bool) obj;
                obj = operandB;
                bool b = (bool) obj;
                switch (operatorType)
                {
                    case "or":
                        return (a || b);
                    case "and":
                        return (a && b);
                    case "equal":
                        return (a == b);
                    case "notequal":
                        return (a != b);
                    default:
                        return false;
                }
            }
            //If the operands are number values.
            else if ((typeof(T) == typeof(int)) || (typeof(T) == typeof(double)))
            {
                //Do something similar but for both int and double
            }
        }


This code works but just does not look right to me. Also in the second part where I look for numbers, I don't know how I can cast to either int or double. Any ideas

If I try to directly put in:

switch (operatorType)
                {
                    case "lessthan":
                        return (operandA < operandB);
                    case "morethan":
                        return (operandA > operandB);
                    case "lessthanequalto":
                        return (operandA <= operandB);
                    case "morethanequalto":
                        return (operandA >= operandB);
                    case "equal":
                        return (operandA == operandB);
                    case "notequal":
                        return (operandA != operandB);
                    default:
                        return false;
                }


I get compiler errors:

Operator '<' cannot be applied to operands of type 'T' and 'T'
.....
.....
AnswerRe: C# Generics - Using operators with generic objects Pin
Christian Graus4-Sep-07 4:43
protectorChristian Graus4-Sep-07 4:43 
GeneralRe: C# Generics - Using operators with generic objects Pin
funkymint4-Sep-07 4:54
funkymint4-Sep-07 4:54 
GeneralRe: C# Generics - Using operators with generic objects Pin
DavidNohejl4-Sep-07 6:09
DavidNohejl4-Sep-07 6:09 
AnswerRe: C# Generics - Using operators with generic objects Pin
Urs Enzler4-Sep-07 4:55
Urs Enzler4-Sep-07 4:55 
GeneralRe: C# Generics - Using operators with generic objects [modified] Pin
funkymint4-Sep-07 5:32
funkymint4-Sep-07 5:32 
GeneralRe: C# Generics - Using operators with generic objects Pin
funkymint4-Sep-07 5:51
funkymint4-Sep-07 5:51 
GeneralRe: C# Generics - Using operators with generic objects Pin
Christian Graus4-Sep-07 6:06
protectorChristian Graus4-Sep-07 6:06 
AnswerRe: C# Generics - Using operators with generic objects Pin
Skippums4-Sep-07 12:47
Skippums4-Sep-07 12:47 
QuestionSerialized objects [modified] Pin
jblouir4-Sep-07 4:15
jblouir4-Sep-07 4:15 
AnswerRe: Serialized objects Pin
led mike4-Sep-07 5:53
led mike4-Sep-07 5:53 
GeneralRe: Serialized objects Pin
jblouir4-Sep-07 5:56
jblouir4-Sep-07 5:56 
Questionhow to import a dll Pin
lune124-Sep-07 4:04
lune124-Sep-07 4:04 
AnswerRe: how to import a dll Pin
N a v a n e e t h4-Sep-07 4:08
N a v a n e e t h4-Sep-07 4:08 
AnswerRe: how to import a dll Pin
Christian Graus4-Sep-07 4:10
protectorChristian Graus4-Sep-07 4:10 
GeneralRe: how to import a dll Pin
lune124-Sep-07 4:45
lune124-Sep-07 4:45 
GeneralRe: how to import a dll Pin
Christian Graus4-Sep-07 5:08
protectorChristian Graus4-Sep-07 5:08 
QuestionTWAIN Implementation/Capabilities in C# .net Pin
gruberdominik4-Sep-07 3:59
gruberdominik4-Sep-07 3:59 

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.