C#基本类型或复杂类型的方法签名?

编程入门 行业动态 更新时间:2024-10-26 08:24:30
本文介绍了C#基本类型或复杂类型的方法签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

什么是使用Primitve类型或复杂类型的优点和缺点是什么?

当你应该使用基本类型在复杂类型,反之亦然?

如:

公共类Person {公共字符串名字{搞定;组; } 公共字符串名字{获得;组; } 公众诠释年龄{搞定;组; } 公众诠释智商{搞定;组; } } 公共无效FooPrimitiveTypes(串名字,字符串姓氏,INT年龄,诠释IQ) { } 公共无效FooComplexTypes(人人) { }

解决方案

  • 要通过每个属性,当你在处理不相交值分别通常使用。此外,有时用在构造函数。坏习惯。

  • 当值与是首选这种方式。

  • 为什么#1是一种不好的做法 - 假设你需要添加高度。我宁愿加入,而不是50方法的另一个特性,更新一个类。

    What are the pros and cons of using Primitve Types or Complex Types?

    When should you use primitive types over complex types and vice versa?

    i.e.:

    public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } public int IQ { get; set; } } public void FooPrimitiveTypes (string firstName, string lastName, int age, int IQ) { } public void FooComplexTypes(Person person) { }

    解决方案

  • To pass each property separately are generally used when you are dealing with disjoint values. Also, sometimes used on constructors. Bad practice.

  • This way is preferred when the values are related.

  • Why #1 is a bad practice - suppose you needed to add height. I'd much rather update one class by adding another property, instead of 50 methods.

    更多推荐

    C#基本类型或复杂类型的方法签名?

    本文发布于:2023-11-16 16:01:26,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1605751.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:类型   方法

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!