Cyclic Constructor in C#
public class Car
{
//Private Member
private int m_CarID=int.MinValue;
private string m_CarType=string.Empty;
private string m_CarName=string.Empty;
private string m_Color=string.Empty;
private string m_Model=string.Empty;
//Constructor
public Car()
{
//default Constructor
}
//Parameterized Constructor
public Car(int carID, string carName)
{
m_CarID = carID;
m_CarName = carName;
}
//Cyclic Constructor
public Car(int carID, string carName, string carType,string carModel):this(carID,carName)
{
m_CarType = carType;
m_Model = carModel;
}
//Cyclic Constructor
public Car(int carID, string carName, string carType, string carModel,string color)
: this(carID, carName,carType,carModel)
{
m_Color = color;
}
}
static void main()
{
Car objCarA=new Car();
Car objCarB=new Car(1,"matiz");
Car objCarC=new Car(1,"matiz","SmallCar","2000");
Car objCarD=new Car(1,"matiz","SmallCar","2000","Dark Green");
}
Validation to Check for Comma separated EmailIDs
List of Email ids separated with [,] Email ID may contain character set as [._-']
^((\w+([-_.']\w+)*@\w+([-_.']\w+)*\.\w+([-_.']\w+)*)*([,])*)*$
Finite automata rule Values should proceed with email Ids with Comma Separated. No comma will precede the email IDs.
abc.xyz@anonymous.com
abc.xyz@anonymous.com,abc-xyz@anonymous.com,abc_xyz@anonymous.com
abc.xyz@anonymous.com,com,D'Souza@anonymous.com
abc.xyz
,abc.xyz@anonymous.com
abc.xyz@anonymous.com,
abc
Javascript
function CheckForCommaSeperatedEmailIDs( fieldValue )
{
var regex = /^((\w+([-_.']\w+)*@\w+([-_.]\w+)*\.\w+([-_.]\w+)*)*([,])*)*$/;
if( !fieldValue.match( regex ) )
{
alert('The Email IDs Invalid');
return false;
}
return true;
}
Validation to check UserID with Period/Dot seperated
1) Ratan.Tata
2) Anil.Dhiru.Ambhani
Ratan.
1) .Mukesh.
2) Amir.khan.
public class Car
{
//Private Member
private int m_CarID=int.MinValue;
private string m_CarType=string.Empty;
private string m_CarName=string.Empty;
private string m_Color=string.Empty;
private string m_Model=string.Empty;
//Constructor
public Car()
{
//default Constructor
}
//Parameterized Constructor
public Car(int carID, string carName)
{
m_CarID = carID;
m_CarName = carName;
}
//Cyclic Constructor
public Car(int carID, string carName, string carType,string carModel):this(carID,carName)
{
m_CarType = carType;
m_Model = carModel;
}
//Cyclic Constructor
public Car(int carID, string carName, string carType, string carModel,string color)
: this(carID, carName,carType,carModel)
{
m_Color = color;
}
}
static void main()
{
Car objCarA=new Car();
Car objCarB=new Car(1,"matiz");
Car objCarC=new Car(1,"matiz","SmallCar","2000");
Car objCarD=new Car(1,"matiz","SmallCar","2000","Dark Green");
}
Validation to Check for Comma separated EmailIDs
Regular Exp Description:
List of Email ids separated with [,] Email ID may contain character set as [._-']
Regular Expression
^((\w+([-_.']\w+)*@\w+([-_.']\w+)*\.\w+([-_.']\w+)*)*([,])*)*$
Regular expression Rules:
Finite automata rule Values should proceed with email Ids with Comma Separated. No comma will precede the email IDs.
Matches:
abc.xyz@anonymous.com
abc.xyz@anonymous.com,abc-xyz@anonymous.com,abc_xyz@anonymous.com
abc.xyz@anonymous.com,com,D'Souza@anonymous.com
Non-Matches:
abc.xyz
,abc.xyz@anonymous.com
abc.xyz@anonymous.com,
abc
Javascript
function CheckForCommaSeperatedEmailIDs( fieldValue )
{
var regex = /^((\w+([-_.']\w+)*@\w+([-_.]\w+)*\.\w+([-_.]\w+)*)*([,])*)*$/;
if( !fieldValue.match( regex ) )
{
alert('The Email IDs Invalid');
return false;
}
return true;
}
Validation to check UserID with Period/Dot seperated
Regular Expression Rules:
Finite automata rule, Values should precede with characters of set [A-Za-z] and followed with period(.) and character set [A-Za-z]Regular Expression:
^[a-zA-Z]+(\.[a-zA-Z]+)+$Matches
1) Ratan.Tata
2) Anil.Dhiru.Ambhani
Non-Matches
Ratan.
1) .Mukesh.
2) Amir.khan.
Regular Expression Logic in Javasctipt
| |||||||||||||||||
Real Time Use Of Static Constructor if you look at above class it is an Utility class and it is consume by Business entity class instance say object Date that has minute component in it. If we have 10 screens that requires minutes to be displayed in dropdownlist in such cases rather then calling 10 calls to database or constructing this collection we prefer calling one instance at the very load of the application which in turns consume by all the pages and across all the users. In the process we have one instance available for all users and across pages. If one see in normal constructor ,one can notice it is invoked after instance is created whereas static constructor is invoked always first and when it is referenced. use System.collection.generics; public class Utility { public static IDictionary static Utility() { m_Minute=new IDictionary m_Minute.Add(1,"00"); m_Minute.Add(2,"15"); m_Minute.Add(3,"30"); m_Minute.Add(3,"45"); } public static IDictionary { return m_Minute; } }
Description :Below javascript code function returns false for entered special character and true for non special character.
Problem Statement:We have scenario where we have data stored in arraylist collection and want to pass this as data as input to Webservice method in string array format.
Namespace: System.collectionsSolution:
|
No comments :
Post a Comment