How To Add IsNumneric Function in C#


That’s right, you can call VB’s IsNumeric() function directly from C#. First add a reference to the Visual Basic compatibility assembly, Microsoft.VisualBasic.dll, which contains the function’s implementation: import namespace using Microsoft.VisualBasic;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="IsNumneric.aspx.cs" Inherits="IsNumneric" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
       <div>
           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
           <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
           <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
   </form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic;

public partial class IsNumneric : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string strValue = TextBox1.Text;
        if (!Information.IsNumeric(strValue))
        {
            Label1.Text = "Is Not Numeric";
        }
        else
        {
            Label1.Text = "Numeric";

        }
    }
}

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru