WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

.NET-Methode mit optionalen Parametern

 

ix

Gast


Beiträge: ---
Anmeldedatum: ---
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 11.01.2011, 19:39     Titel: .NET-Methode mit optionalen Parametern
  Antworten mit Zitat      
Hallo,
ich möchte Methoden eine .NET-Klasse, welche optionale Parameter enthält, verwenden. Dazu habe ich eine kleine Testklasse geschrieben. Leider funktioniert die Verwendung des Platzhalters [] nur für System.String Parameter. Für Integer und Boolean bekomme ich die Meldung, dass keine Methonde dieser Signatur vorhanden ist. Hat jemand ein Idee.

Mein Matlab Code:
Code:


assembly = NET.addAssembly('D:\net_test\test_lib\test_lib\bin\Release\test_lib.dll');
math = test_lib.Math

math.add(1, 2)
math.add_optional(10, 20, 30)
math.add_optional(10, 20, []) % Signaturfehler

math.combine('string1', ' string2')
math.combine(System.String('sys string1'), System.String(' sys string2'))

math.combine_optional('', '', [])
math.combine_optional('string1' , ' string2', [])
math.combine_optional('string1' , ' string2', ' sting3')
 
math.logic(logical(1), logical(1))
math.logic(logical(1), logical(0))
math.logic(1, 0)

math.logic_optional(logical(1), logical(1), logical(1))
math.logic_optional(logical(1), logical(0), logical(1))
math.logic_optional(logical(1), logical(0), []) % Signaturfehler

 


Mein VB.Net-Code
Code:


Public Class Math
    Public Function add(ByVal value1 As Integer, _
                        ByVal value2 As Integer) As Integer

        Return value1 + value2
    End Function

    Public Function add_optional(ByVal value1 As Integer, _
                                 ByVal value2 As Integer, _
                                 Optional ByVal value3 As Integer = 0) As Integer

        Return value1 + value2 + value3
    End Function


    Public Function combine(ByVal string1 As String, _
                            ByVal string2 As String) As String

        Return String.Concat(string1, string2)
    End Function

    Public Function combine_optional(ByVal string1 As String, _
                                     ByVal string2 As String, _
                                     Optional ByVal string3 As String = "") As String

        Return String.Concat(string1, string2, string3)
    End Function

    Public Function logic(ByVal bool1 As Boolean, _
                          ByVal bool2 As Boolean) As String
        Dim result As String

        If (bool1 And bool2) Then
            result = "All True"
        Else
            result = "Not All True"
        End If

        Return result
    End Function

    Public Function logic_optional(ByVal bool1 As Boolean, _
                      ByVal bool2 As Boolean, _
                      Optional ByVal bool3 As Boolean = False) As String
        Dim result As String

        If (bool1 And bool2 And bool3) Then
            result = "All True"
        Else
            result = "Not All True"
        End If

        Return result
    End Function
End Class

 


Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2025 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.