You need to ensure that the method extracts a list of URLs that match the following pattern: @http://(www\.)?([^\.]+)\.com; Which code should you insert at line 07?

You write the following method (line numbers are included for reference only):

You need to ensure that the method extracts a list of URLs that match the following pattern:
@http://(www\.)?([^\.]+)\.com;
Which code should you insert at line 07?

You write the following method (line numbers are included for reference only):

You need to ensure that the method extracts a list of URLs that match the following pattern:
@http://(www\.)?([^\.]+)\.com;
Which code should you insert at line 07?

A.
Option A

B.
Option B

C.
Option C

D.
Option D

Explanation:
The MatchCollection.GetEnumerator method returns an enumerator that iterates through a
collection.
Note:
The MatchCollection Class represents the set of successful matches found by iteratively applying a
regular expression pattern to the input string.

MatchCollection.GetEnumerator Method
https://msdn.microsoft.com/enus/library/system.text.regularexpressions.matchcollection.getenumerator(v=vs.110).aspx



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Hans Werner

Hans Werner

The correct answer is C!

rao

rao

I Agree

zerocool

zerocool

True
Both, A & B, throw an invalid cast exception.

fabrizio

fabrizio

i dont understand, is the real test bugged too so i’ve to check A?.
Or the bug is only in this page so in the exam i’ve to answer C?

Lonewolf

Lonewolf

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.RegularExpressions;
using System.Linq;

public class Program
{
public static List Test(string url)
{
const string pattern = @”http://(www\.)?([^\.]+)\.com”;
List result = new List();

MatchCollection myMatches = Regex.Matches(url,pattern);

//foreach(Match curr in myMatches)
// result.Add(curr.Value);

result = (from Match m in myMatches
select m.Value).ToList();

//result = (List)myMatches.GetEnumerator();

return result;
}
public static void Main()
{
string url = “http://www.a.com”;
List result = Test(url);
Console.WriteLine(result[0]);

}
}

Lonewolf

Lonewolf

it’s tested and proved.