Skip to content

Need help in method parameter type.

Rahul Khanna

Asked Jan 26, 2011, 2:56 AM EST3 answers
Share
LinkedInX
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.
Code
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. 

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    As far as I understoof from your question the solution may be this : if((studentid== "")&&(feeamount=="") &&(collectiondate=="") { Console.WriteLine("Studentid,Feeamount and collection date could not be left blank"); } in case of GUI change Console.WriteLine into : MessageBox.Show("Studentid,Feeamount and collection date could not be left blank");
    0
  • 0
    public string CollectFee(string studentid, decimal feeamount, DateTime collectiondate) 
    { 
       
    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.  
    }
    0
  • Suthish Nair
    0
    If this query got resolved then please Accept the post that helped you as Answer.

    So other members can easily find the answers.
    0