Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I get the following errors on the following code.

Error 1 The out parameter 'dtValueToCheck' must be assigned to before control leaves the current method

Error 2 The out parameter 'strValueToCheck' must be assigned to before control leaves the current method

Error 3 The out parameter 'strFieldNameToCheck' must be assigned to before control leaves the current method

Error 5 No overload for method 'ValidateCriteria' takes 5 arguments

What am I doing wrong please?
Thanks

C#
private bool ValidateAssetCriteria(DataTable dtToCheck, string strAssetName)
        {
            string strFieldNameToCheck = string.Empty;
            string strValueToCheck = string.Empty;
            DateTime dtValueToCheck = DateTime.Now;

            bool validate = ValidateCriteria(dtToCheck, strAssetName,
                                                           out strFieldNameToCheck, out strValueToCheck,
                                                           out dtValueToCheck);

           
        }

public static bool ValidateCriteria(DataTable dtToCheck, string strAssetName,
                                            out string strFieldNameToCheck, out string strValueToCheck,
                                            out DateTime dtValueToCheck)
        {

...
...
strFieldNameToCheck = "fieldname";
strValueToCheck = "value";
dtValueToCheck = DateTime.now

}
Posted

I'm betting you have a return statement before the code block you included in the ValidateCriteria and thus the parameters has not been set.

You have to set the three out parameters before any return statement.
 
Share this answer
 
Comments
Espen Harlinn 15-Oct-11 4:22am    
Right :)
The clue's in the error message. An out parameter must be assigned, however the method executes, i.e. there must be no way of returning from the method without assigning them.

If you're passing out parameters, there's no point initialising them first; the method you pass to them must assign new values. If you want your method to be able to, but not required to, update the values, you should use ref, not out.

I guess the parameter count message is because these two things are in different projects and the compile on the first fails, because it looks like five parameters from here.
 
Share this answer
 
Comments
[no name] 14-Oct-11 11:15am    
Clear answer
+5
arkiboys 14-Oct-11 11:41am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900