Kirti Deshpande

Kirti Deshpande

  • NA
  • 108
  • 17k

How to Optimize the code with ternary conditional operator ?:

May 10 2021 3:55 PM
How can I Optimize below code with ternary conditional operator ?:
 
I am new to Linq Need to know some optimization with   operator ?:
 
Thank you
  1. private string GetFunctionId(FunctionType functionType)  
  2. {  
  3.    
  4. string _Id;  
  5. int _Count;  
  6. if (functionType == FunctionType.abc)  
  7. {  
  8. _Count = Collection.Where(f => f.Function == functionType).Count();  
  9. _Id = String.Format("{0}{1}""A", Count + 1);  
  10. return _Id;  
  11. }  
  12. else  
  13. {  
  14. Count = Collection.Where(f => f.Function != TimeProgramFunctionType.FunctionType).Count();  
  15. _Id = String.Format("{0}{1}""B", Count + 1);  
  16. return _Id;  
  17. }  
  18. }  
Output should Be
 
if true A1,A2,A3
else B1,B2,B3 

Answers (1)