Click here to Skip to main content
15,742,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public int UpdateMC(Guid id
         , string description
         , decimal score
         , string optionA
         , string optionB
         , string optionC
         , string optionD
         , int optionAnswer
         , bool allowUploadAttachment = false
         , byte[] optionAImage = null
         , byte[] optionBImage = null
         , byte[] optionCImage = null
         , byte[] optionDImage = null
         , string optionAImageFileExtension = null
         , string optionBImageFileExtension = null
         , string optionCImageFileExtension = null
         , string optionDImageFileExtension = null
         , bool clearOptionAImage = false
         , bool clearOptionBImage = false
         , bool clearOptionCImage = false
         , bool clearOptionDImage = false
         , byte[] image = null
         , string imageFileExtension = null
         , bool clearImage = false
         , byte[] attachment = null
         , string attachmentFileExtension = null
         , bool clearAttachment = false){}

I have some methods like above. The parameters are properties of a class, but those methods will take different combo to process,(I mean, some methods will only take a few of them, but some will take almost all). My question is: should I wrap them into on object and then pass that to the method? Because it's obviously a bit too long if I seperate them. Is there any difference of theses two way to pass parameters? Which is more efficient or more standard?

What I have tried:

[nothing needs to be tried here at the moment.]
Updated 29-May-16 23:42pm

1 solution

For that many parameters, I'd probably use a class - and I'd probably create one which held option, optionImage, optionImageFileExtension, and clearOptionImage, and use params to pass a number of them through:
public int UpdateMC(Guid Id, string description, decimal score, int optionAnswer, params MyClass[] options)

And if some need all of the parameters, I'd probably create a class that held them all:
public class MyParameterClass
         public string description {get; set;}
         public decimal score {get; set;}
         public int optionAnswer {get; set;}
         public bool allowUploadAttachment {get; set;}
         public byte[] image{get; set;}
         public string imageFileExtension {get; set;}
         public bool clearImage {get; set;}
         public byte[] attachment {get; set;}
         public string attachmentFileExtension {get; set;}
         public bool clearAttachment {get; set;}
         public List<MyClass> options {get; set;}
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