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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:50:39+00:00 2026-05-15T21:50:39+00:00

How would I convert this to C# from VB.net. I tried the online converters

  • 0

How would I convert this to C# from VB.net. I tried the online converters but I got errors when I put it in my project.

Dim regexinfo As String = String.Empty
Dim p = "\[news\](?<info>.*?)\[/news\]"
Dim Matches = Regex.Matches(response, p, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
If Matches IsNot Nothing AndAlso Matches.Count > 0 Then
    For Each Match As Match In Matches
        If Match.Groups("info").Success Then
            regexinfo = (Match.Groups("info").Value)
        End If
    Next
End If
  • 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-05-15T21:50:40+00:00Added an answer on May 15, 2026 at 9:50 pm

    I’m guessing it’s the “Match” variable named the same as it’s type that’s causing problems. This should do what you want:

    var p = @"\[news\](?<info>.*?)\[/news\]";
    var Matches = Regex.Matches(response, p, RegexOptions.IgnoreCase | RegexOptions.Singleline);
    string regexinfo = Matches.LastOrDefault(m=>m.Groups("info").Success) ?? string.Empty;
    

    This code is functionally equivalent to your original VB.Net, even though it’s only 3 lines instead of 10 (and it could easily be just 1).

    For example, the “if” condition in the original code was not needed, as the Matches() function will return an empty collection rather than null and ?? string.Empty() snippet takes care of the not-found case. So even though the code changed, the behavior did not. This isn’t a c# vs VB thing, though; VB.Net could do it in one line as well. You might want to make a further improvement by using FirstOrDefault() rather than LastOrDefault(). It’s just that latter matches up with you original and former does not.

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

Sidebar

Related Questions

How would I convert this kind of expression in VB.NET? I'm stomped! bool exists=repo.Exists<Post>(x=>x.Title==My
I need to convert this line of code from an asp.net c# page to
I'm trying to convert quite big project from .net 3.5 to .net 4.0 and
how would you convert this array: Array ( [0] => Array ( [Contact] =>
I would like to convert this piece of logic with purely matrix operations instead
I would like to convert this string foo_utf = u'nästy chäräctörs with å and
I would like to convert this fluent approach to xml: container.Register( AllTypes.FromAssemblyNamed(Company.DataAccess) .BasedOn(typeof(IReadDao<>)).WithService.FromInterface(), AllTypes.FromAssemblyNamed(Framework.DataAccess.NHibernateProvider)
I'm trying to convert this line into Batch how would one start this exe
I would like to convert a yyyy-mm-dd to something like this: Saturday, 2 October
How would you to convert or cast a List<T> to EntityCollection<T> ? Sometimes this

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.