why we need to pass Boolean value to the method [closed]
I have confusion on below code i.e why we need to pass Boolean value to the method and what it returns?
RefreshLookupList(false);
private void RefreshLookupList(bool forExport)
{
grdLists.Rows.Clear();
grdLists.DataSource = Lists.GetListItems(cboListType.SelectedValue);
grdLists.DataBind();
lblCount.InnerText = "Lookups: " + grdLists.Rows.Count.ToString();
开发者_Go百科}
In that particular case the parameter is not used. However it may not be safe to remove it from the method signature. It might be there specifically to change the signature in order to avoid a naming clash with another method.
Bad form really, but sometimes necessary.
Personally I'd try to remove it. If it doesn't compile when you remove it because of a clash with a similarly named method, I'd leave it there, but make the parameter default (if you are using C# 4). I say leave it there because someone may be using reflection to reference it.
If you know that reflection isn't used in the application, right-click refactor the method name in Visual Studio and rename it, this will rename all references too (but not literal references for reflection). Then remove the parameter.
Looks like a stale old parameter. Delete it.
The method does not return anything.
From the code you have posted, it doesn't require the boolean parameter at all, you could remove it from the method signature and see if you code still compiles.
hmm you need to pass the boolean value because the signature of the method ask for one
and it return "nothing" since it's declared as void, it's a method, not a function / property
forExport
isn't used, but an earlier implementation might have done. Ie. "for historical reasons".
Check the history of the function in version control.
It looks like it is never used and the method doesn't return anything.
Well, if this is the WHOLE method, then passing the value of forExport
means nothing.
The method doesn't use the parameter whatsoever.
And the return value of a void method is null.
The forExport variable is never used so is effectively redundant. This method may have been re-factored and the method variable not removed.
Well if that's the entire code block then you don't need to pass it at all. You can remove it.
Do a search on the code for the method and find out what else calls it. If nothing does then you can safely remove it.
Give it a go, and try to recompile the code. Good luck
精彩评论