Call String method inside another in C# and VB.Net

Last Reply 7 months ago By pandeyism

Posted 7 months ago

How to call string method to another method in C# ?

Posted 7 months ago

Hi SUJAYS,

Please refer below sample.

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    string message = "Mudassar Khan";
    Response.Write("Length of <b> " + message + "</b> is : <b> " + GetLength(message) + "</b>");
}

public int GetLength(string name)
{
    return GetString(name).Length;
}

public string GetString(string strvalue)
{
    return strvalue;
}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    Dim message As String = "Mudassar Khan"
    Response.Write("Length of <b> " & message & "</b> is : <b> " & GetLength(message) & "</b>")
End Sub

Public Function GetLength(ByVal name As String) As Integer
    Return GetString(name).Length
End Function

Public Function GetString(ByVal strvalue As String) As String
    Return strvalue
End Function

Output

Length of Mudassar Khan is : 13