Click here to Skip to main content
15,906,081 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if(xyz==1)
{
if(searchFilter.FormId == 0 || SubTab.AppType == searchFilter.FormId)
{
	Some 50 Line co code 
}	
}

else (searchFilter.FormId == 0 || SubTab.AppType == searchFilter.FormId || (SubTab.AppType == (int)_partner.Form.Homeless) && searchFilter.FormId != null)
{
		Some 50 Line co code 
}

Note : both "Some 50 Line co code "" lines of code are same , so can I do this in another way to not repeat same code, what should have to do for the same, 


What I have tried:

<pre>if(xyz==1)
{
if(searchFilter.FormId == 0 || SubTab.AppType == searchFilter.FormId)
{
	Some 50 Line co code 
}	
}

else (searchFilter.FormId == 0 || SubTab.AppType == searchFilter.FormId || (SubTab.AppType == (int)_partner.Form.Homeless) && searchFilter.FormId != null)
{
		Some 50 Line co code 
}

Note : both "Some 50 Line co code "" lines of code are same , so can I do this in another way to not repeat same code, what should have to do for the same, 
Posted
Updated 2-Jul-18 21:53pm

The way to consolidate code is to create a method/function and put the duplicate code in it and call it from the the duplicate places.
 
Share this answer
 
Comments
Maciej Los 3-Jul-18 3:51am    
Short And To The Point!
5!
In addition to Mehdi Gholam[^]'s answer, i'd like to provide a link to MSDN documentation: Methods (C# Programming Guide) | Microsoft Docs[^], which explains how to create method.
 
Share this answer
 

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

  Print Answers RSS


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