且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

[C#]我应该将方法的所有(或某些)参数包装到对象中吗?

更新时间:2021-11-09 23:13:11

对于那么多参数,我可能使用一个类 - 我可能会创建一个包含option,optionImage,optionImageFileExtension和clearOptionImage的类,并使用 params 来传递它们中的一些:

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;}
   }