www.webdeveloper.com
Results 1 to 3 of 3

Thread: ASP.NET C# Multiple possible return types

Hybrid View

  1. #1
    Join Date
    Mar 2010
    Posts
    11

    Exclamation ASP.NET C# Multiple possible return types

    Hey Everyone,

    I'm wanting to create a fuction that has 2 or more possible return types if thats possible. I.E

    PHP Code:

    public StringBoolean testfunction(string inputstring returntype="boolean"){
    if(
    input == "String" && returntype=="boolean")
    return 
    true;
    else
    return 
    false;

    if(
    input == "String" && returntype=="string")
    return 
    "string is equal to string";
    else
    return 
    "string is not equal to string";

    Thanks for any help you can give

  2. #2
    Join Date
    Mar 2010
    Location
    Cape Girardeau,MO
    Posts
    3

    ASP.NET VB Multiple possible return types

    This is by far not the best way but it would work...

    Create three functions that will do the checks for you. I hope this helps

    Code:
    Public Overridable Function CheckThis(ByVal input As Object) As Object
            Dim something As Object = Nothing
            If isBool(input) = True Then
                something = True
            ElseIf isString(input) = "yes" Then
                something = "Is String"
            End If
            Return something
        End Function
    
        Public Overridable Function isBool(ByVal input As Object) As Object
            If TypeOf input Is Boolean Then
                Return True
            Else
                Return False
            End If
        End Function
    
        Public Overridable Function isString(ByVal input As Object) As Object
            If TypeOf input Is String Then
                Return "yes"
            Else
                Return "not string"
            End If
        End Function
    Thanks,
    Matt
    inCase Studio
    http://incasestudio.com

  3. #3
    Join Date
    Mar 2010
    Posts
    11

    Smile Thanks

    Hi Matt,

    Thanks for that what i'm aiming to do is create a easy SQL database class this class includes a query function this function splits the query string by ';' and exetues each query if the query is a "SELECT" query it will return a dataset, if it is a "INSERT INTO", "UPDATE", "DELETE" it will return an int of the number of rows inserted, updated or deleted. So this function will return only one object but it could one of two possible datatypes.. is it possible to have a function with 2 possible return datatypes?

    My prefered ASP.NET coding language is C# so any help in this lanugage would be better.

    Thanks,

    Chris

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles