Xavi S

Xavi S

  • NA
  • 20
  • 6.2k

c# best coding pattern

Nov 28 2014 1:52 AM
Hi , 
 
I would like to know , which is the best way to do in a situation am facing now . Actually issue is a simple one and have the solution for that . But to know , which is the best . That's why am posting here .
 
I have a simple method  . In the method , i want to set for 2 arguements accotding to the situation . Situation can solve , if it implement it in 2 methods . But i want to know , is there any other way to do it as a part of optimizing the code . here is my code .
 
//EncoderParamters is a class .  
private EncoderParameters encoderparam = GetEncoderParameters(); 
 
//Method definition .  
private static EncoderParameters GetEncoderParameters()
{
myencoderparameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.Compression, (long)EncoderValue.CompressionCCITT4);
return myencoderparameters;
}
 
In the method , i have to set for 2 arguements when it comes for CCITT4 and CCITLWZ . Currently it is set for CCITT4 . but a situation will come the same method need to call for CCITLWZ compression .
 
//Method call area .  
resultBitmap.Save(newImageName, this.imagecodec, this.encoderparam); 
 
We are going to have a step the same save method , but when call this.encoderparam , it should execute the method GetEncoderParameters() with the second arguement . I know that , if we do in another method and call . Also can set a parameter says bool, string and all , we can do it in that way also . I need to know , accepting the c# coding principle , is there any best way to handle this situation ?
 
Advance  Thanks
 
Xavi  
 
 
 
 

Answers (1)