使用仅带有属性和构造函数的类 [英] use of a class with just properties and constructors

查看:80
本文介绍了使用仅带有属性和构造函数的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅具有属性和构造函数且没有方法的类的用途是什么?
请详细说明或参考...
实际上,我已经分配了一个维护项目.我在该项目中看到了很多这样的类.


问候.

What is the use of a class with just properties and constructors and NO METHODS ?
Please explain in detail or refer...
Actually, I have been assigned a project for maintainence. and i see a lot of such classes in that project.


Regards.

推荐答案

难怪,我已经看到这样的类用于简单地存储有关各种实体的信息(例如C ++中的结构-C#结构非常罕见).或多次传递参数.这些类可以稍后进行序列化,写入数据库或从数据库中读取(等等,后者更常见,有些人只是喜欢将数据库结构映射到类结构:)).
No wonder, I''ve seen such classes being used to simply store information about various entities (like structs in C++ - C# structs are quite rare) or to pass arguments many times. These classes could later be serialized, written to/read from database etc (the latter more often, it some people just love to map database structure to class structure :) ).


通常,它们要么只是存储相关信息并将其保持在一起,要么是从现有的类派生而来-添加功能而不添加功能.例如,一个类可以从List派生而没有添加任何方法:
Generally, they are to either just store relevant information and keep it together, or to derive from an existing class - adding functionality without adding functions. For example a class could derive from List and add no methods:
public class Students : List<student>
   {
   public string ClassName { get; set; }
   }


这篇关于使用仅带有属性和构造函数的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆