Hi all,
i have a method say for student fee collection, in that there are three parameter studid,feeamount, collection date. method defination is like below.
public string CollectFee(string studentid, decimal feeamount, DateTime collectiondate)
{
}
In this while calling this method from presentation layer..user must have to have enter all the parameter if any of the parameter is missing he will get message like....studentid and feeamount and collection date is required. i want to check these while impleting the CollectFee method, since the method parameter having string, decimal, datetime datatype, how can i check empty or not for these in one if condition.
Suthish NairPosted Jan 30, 2011, 1:18 PM
So other members can easily find the answers.
knightsPosted Jan 26, 2011, 12:53 PM
{
if (studentid== null)
{
throw new ArgumentNullException("studentid Cannot be Empty or Null");
}
//You can put similar If statement for each argument so that each missing argument can be detected and notified
OR -- the following can be done in 1 statment with a generic message telling that one of the arguments provided were empty or null
if (studentid == null || feeamount == null || collectiondate == null)
{
throw new ArgumentNullException("One of the provided arguments is Empty or Null");
}
//Rest of the implimentation can go here, after you have checked that your arguments are not null.
}
Shahrukh KhanPosted Jan 26, 2011, 12:09 PM