Convert vb.net code snippet in C #

Visual Studio 2005.

I converted part of my source code in C #.

However, when I took a snapshot of the code below, I noticed that I do not have an IsNumber method.

Why isnumber missing? I wanted to use it so that I could force the user to enter only numbers.

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar.IsNumber(e.KeyChar) = False Then
            e.Handled = True
        End If
End Sub

Thanks so much for any suggestions,

+3
source share
4 answers

use static char.IsNumber():

char.IsNumber(e.KeyChar);

By the way, I think you want to use char.IsDigit()instead. This comes from the MSDN website:

IsNumber()determines if Char is any Unicode number category. This contrasts with IsDigit(), which determines if Char is a radix-10 digit.

, IsNumber() true , 六 ( '6').

+7

# , .

VB.

1 , , ; .

# - . char.IsNumber - ; .

public class Example1
{
    public static int Test() { return 0; }

    public Example1()
    {
        this.Test();  // This doesn't work
        Example1.Test();  // This does
    }
}
+3

solvable.

The following was used:

    if (char.IsNumber(e.KeyChar) == false)
    {
        e.Handled = true;
    }
0
source

we usually use developer merging to convert code from vb.net to c # and vice versa. You can also try.

0
source

Source: https://habr.com/ru/post/1795937/


All Articles