Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7983749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:03:23+00:00 2026-06-04T11:03:23+00:00

How does VB.NET calculate the length of a method? How can I do this

  • 0

How does VB.NET calculate the length of a method? How can I do this in C#?

This my VB.NET code:

Private Function ZeroPad(ByRef pNumber As Integer, ByRef pLength As Integer) As String
    Dim Padding As Object
    If IsNumeric(pNumber) And IsNumeric(pLength) Then
        Padding = New String("0", pLength)
        ZeroPad = Padding & CStr(pNumber)
        ZeroPad = Right(ZeroPad, pLength)
    Else
        ZeroPad = CStr(pNumber)
    End If
End Function

I converted into C# as follows:

private string ZeroPad(ref int pNumber, ref int pLength) {
    object Padding;
    if ((IsNumeric(pNumber) && IsNumeric(pLength))) {
        Padding = new string("0", pLength);
        return (Padding + pNumber.ToString());

        ZeroPad = ZeroPad.Substring((ZeroPad.Length - pLength));

        // In the above line, how can I take the length of a method in C#?
    }
    else {
        return pNumber.ToString();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:03:25+00:00Added an answer on June 4, 2026 at 11:03 am

    You are probably confused between the variable ZeroPad and the method ZeroPad. It is customary to write variable names with a lower case initial character, e.g. zeroPad. To return a value from a method, use return in C#. I’m not sure what the purpose is of your IsNumeric subroutine or why you take value by reference, but your code in C# would be similar to:

    private string ZeroPad(ref int pNumber, ref int pLength)
    {
        string padding;
        string zeroPad;
        if ((IsNumeric(pNumber) && IsNumeric(pLength)))
        {
            padding = new string('0', pLength);
            zeroPad = (padding + pNumber.ToString());
    
            zeroPad = zeroPad.Substring((zeroPad.Length - pLength));
        }
        else
        {
            zeroPad = pNumber.ToString();
        }
        return zeroPad;
    }
    

    As you don’t change the values of pNumber or pLength, you can pass them by value (ByVal in Visual Basic). And knowing that both pNumber and pLength are integers, and therefore always numeric, your method could be shortened to the following:

    private string ZeroPad(int pNumber, int pLength)
    {
        string zeroPad;
        string padding = new string('0', pLength);
    
        zeroPad = (padding + pNumber.ToString());
    
        zeroPad = zeroPad.Substring(zeroPad.Length - pLength);
    
        return zeroPad;
    }
    

    The .NET Framework’s Base Class Libraries have a String.PadRight method that does exactly what you want if you specify '0' as the value for paddingChar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does .net have the equivilent of Delphi's QuotedStr function. This replaces all quotes with
Does .NET have a built-in method to calculate the ULP of a given double
In .net 4.0 dictionary I know I can calculate the sum of all integer
Does .NET have some type of built in function that allows filtering on Gridviews?
Does ASP.NET MVC provide any way to implement UpdateProgress WebForms control analog? Can anyone
Does dot net 3.5 provides some api to calculate crc32 for input data?I have
(can skip this part just an explanation of the code below. my problems are
Does anyone happen to know if, in .NET (4.0, if it matters), the Length
I have a .NET function that does some complex calculation. Depending on the parameters
Does .NET natively support anything similar to PHP's variable variables ? If not, how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.