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 8069583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:05:48+00:00 2026-06-05T13:05:48+00:00

have a php code like this,going to convert it in to C#. function isValid($n){

  • 0

have a php code like this,going to convert it in to C#.

function isValid($n){
if (preg_match("/\d+/",$n) > 0 && $n<1000) {
    return true;
}
return false;
}

Here is my try,BUT error shown Error is “expected class, delegate, enum, interface or struct error C#”

public string IsValidate(string Item)
{
    string Result = Item;
   try
{
Result = System.Text.RegularExpressions.Regex.Replace(InputTxt, @"(\\)([\000\010\011\012\015\032\042\047\134\140])", "$2");
}
catch(Exception ex)
{
console.WriteLine(ex.Message)
}
return Result;
}

What is the error,Is there any other way to implement this better than my try ?
i got this snippet from here code

  • 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-05T13:05:51+00:00Added an answer on June 5, 2026 at 1:05 pm

    You haven’t define this method inside a class/struct that is why you are getting this error. You may define this method inside a class.

    public class MyValidator
        {
            public string IsValidate(string Item)
            {
              //Your code here
            }
    
        }
    

    Later you can use it like:

    MyValidator validator = new MyValidator();
    validator.IsValid("Your string");
    

    Also you are missing semicolon at the end of the Console.Write statement, plus ‘c’ for Console should be in uppercase

    Edit:
    Since in your php code, it looks like you are trying to see if the string passed is an integer and it is less than 1000, you may use the int.TryParse like the following:

    public class MyValidator
    {
        public bool IsValidate(string Item)
        {
            string Result = Item;
            int val;
            if (int.TryParse(Item, out val) && val > 0 && val < 1000)
            {
                return true;
            }
            else
            {
                return false;
            }
    
        }
    }
    

    In you main method you can do:

     static void Main()
            {
                MyValidator validator = new MyValidator();
                Console.WriteLine(validator.IsValidate("asdf123")); // This will print false
                Console.WriteLine(validator.IsValidate("999")); //This will print true
                Console.WriteLine(validator.IsValidate("1001")); //This will print false
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php code like this,going to convert it in to C#. function
have a php code like this,(part of the php function here)going to convert it
I have a bit of php code like this: $test = <!--my comment goes
I have code like this: <?php if ($this->session->userdata('permission') == 4 || $this->session->userdata('permission') == 3)
I have code like this: <?php if(isset($global_info_results)): ?> <?php echo count($global_info_results) ?> <span>Mali Oglasi:
I have code like this: <ul> <?php foreach($persons as $key) : ?> <?php if($this->session->userdata('id_user')
In PHP, say that you have some code like this: $infrastructure = mt_rand(0,100); if
I've used this code to have a like btn on my site: <iframe src=http://www.facebook.com/plugins/like.php?href=URL_OF_YOUR_WEBSITE&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80&amp
So I have some PHP code that looks like: $message = 'Here is the
I have code that looks like the following: <form id=MyForm name=MyForm method=post action=index.php> <input

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.