Hi ahmedsa,
Refer below sample code.
C#
protected void Page_Load(object sender, EventArgs e)
{
List<string> collection = new List<string>();
var config = new Enumerator
{
MinLength = 3,
MaxLength = 10,
StartWithCapitalLetter = true
};
var enumerator = new CustomEnumerator(collection, config);
foreach (string s in enumerator)
{
if (s.Length >= config.MinLength && s.Length <= config.MaxLength && char.IsUpper(s.ToCharArray()[0]))
{
collection.Add(s);
}
}
}
public class CustomEnumerator : IEnumerable<string>
{
public CustomEnumerator(IEnumerable<string> collection, Enumerator config)
{
throw new NotImplementedException();
}
public IEnumerator<string> GetEnumerator()
{
throw new NotImplementedException();
}
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
}
public class Enumerator
{
private int _minLength = -1;
public int MinLength
{
get { return _minLength; }
set { _minLength = value; }
}
private int _maxLength = -1;
public int MaxLength
{
get { return _maxLength; }
set { _maxLength = value; }
}
private bool _startWithCapitalLetter ;
public bool StartWithCapitalLetter
{
get { return _startWithCapitalLetter; }
set { _startWithCapitalLetter = value; }
}
private bool _startWithDigit ;
public bool StartWithDigit
{
get { return _startWithDigit; }
set { _startWithDigit = value; }
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim collection As List(Of String) = New List(Of String)()
Dim config = New Enumerator With {
.MinLength = 3,
.MaxLength = 10,
.StartWithCapitalLetter = True
}
Dim enumerator = New CustomEnumerator(collection, config)
For Each s As String In enumerator
If s.Length >= config.MinLength AndAlso s.Length <= config.MaxLength AndAlso Char.IsUpper(s.ToCharArray() (0)) Then
collection.Add(s)
End If
Next
End Sub
Public Class CustomEnumerator
Inherits IEnumerable(Of String)
Public Sub New(ByVal collection As IEnumerable(Of String), ByVal config As Enumerator)
Throw New NotImplementedException()
End Sub
Public Function GetEnumerator() As IEnumerator(Of String)
Throw New NotImplementedException()
End Function
Private Function GetEnumerator() As IEnumerator
Throw New NotImplementedException()
End Function
End Class
Public Class Enumerator
Private _minLength As Integer = -1
Public Property MinLength As Integer
Get
Return _minLength
End Get
Set(ByVal value As Integer)
_minLength = value
End Set
End Property
Private _maxLength As Integer = -1
Public Property MaxLength As Integer
Get
Return _maxLength
End Get
Set(ByVal value As Integer)
_maxLength = value
End Set
End Property
Private _startWithCapitalLetter As Boolean
Public Property StartWithCapitalLetter As Boolean
Get
Return _startWithCapitalLetter
End Get
Set(ByVal value As Boolean)
_startWithCapitalLetter = value
End Set
End Property
Private _startWithDigit As Boolean
Public Property StartWithDigit As Boolean
Get
Return _startWithDigit
End Get
Set(ByVal value As Boolean)
_startWithDigit = value
End Set
End Property
End Class