类概念 [英] Classes concepts

查看:75
本文介绍了类概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


实际上是我在OOP的新手,我想知道这种方式是否使用了一个最好的方式(合乎逻辑的,好的方式)


假设我有一个部门的数据库(depid,depname)


如果我做的话上课


公共类部门

{

private int id;

私人字符串名称;


public int ID

{

get {return id;}

set {id =值;}

}

公共字符串名称

{

得到{返回名称;}

设置{name = value;}

}

}


我想要的是创建一个类对于每个部门我再做一个

课程:


公共类部门

{

私人部门[] ListofDepartments;


公共部门()

{

//想象一下,我有一个包含所有查询的数据表(从
中选择*
部门)

ListofDepartments =新部门[datatable.rows.count];

//想象一下我做一个循环= for i = 0到行数据表

ListofDepartments [i] =新部门()

//分配到ListofDepartments [i] .ID并命名
$ b的值$ b datatable

}

}


这是创建这个的好方法吗?

你能给我一个关于可以在

系类课程中实现的方法的例子(第一个)

非常感谢

问候。

Josema

Hi to all,

actually im a newbie in the OOP and i would like to know if this way of
using clases its a best way (logical, and a good way)

Lets imagine that i have a data base with departments (depid, depname)

if i make the class

public class department
{
private int id;
private string name;

public int ID
{
get{return id;}
set{id=value;}
}
public string Name
{
get{return name;}
set{name=value;}
}
}

like which I want is to create a class for each department i make another
class:

public class departments
{
private department[] ListofDepartments;

public departments()
{
//Imagine that i have a datatable with all the query (select * from
departments)
ListofDepartments=new departament[datatable.rows.count];
//Imagine that i make a loop = for i=0 to rows into the datatable
ListofDepartments[i]=new Department()
//assing into the ListofDepartments[i].ID and Name the values of the
datatable
}
}

Its this a good way to create this?,

Could you put me an example about wich methods could be implemented in the
department class (the first)
Thanks a lot
Regards.
Josema

推荐答案

Josema,


对于什么你正试图这样做,我认为有更好的方法可以做到这一点

吧。首先,类名应该是Department,而不是department。


对于集合类,我将从CollectionBase派生,并在

..NET 2.0中,我会使用List< T>代表

部门的集合。


然而,我根本不会这样做。最后,我将使用在IDE中设置的类型化的

数据集并使用它们。它将为数据提供最简单的
访问权限,并将这些分组提供给您需要的
集合。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com

" Josema" <济****** @ ocu.org>在消息中写道

新闻:80 ********************************** @ microsof t.com ...
Josema,

For what you are trying to do, I think there are some better ways to do
it. First, the class name should be Department, and not department.

For the collection class, I would derive from CollectionBase, and in
..NET 2.0, I would use the List<T> class to represent the collection of
department.

However, I wouldn''t even do this at all. In the end, I would use typed
data sets set up in the IDE and use those. It would provide the easiest
access for the data, as well as offering that grouping into collections that
you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Josema" <Je******@ocu.org> wrote in message
news:80**********************************@microsof t.com...
大家好,

实际上我是OOP中的新手,我想知道这种方式是否使用了clases一种最好的方式(合乎逻辑的,好的方式)

让我们想象一下我有一个部门的数据库(depid,depname)

如果我上课

公共类部门
{private int id;
私人字符串名称;

public int ID
{
获取{return id;}
设置{id = value;}
}
公共字符串名称
{
获取{返回名称;}
设置{name = value;}
}


就像我想要的是为每个部门创建一个班级我再做一个班级:
公共级部门
{私人部门[] ListofDepartments;

公共部门()
//
//想象一下我有一个包含所有查询的数据表(选择*来自
部门)
ListofDepartments = new departament [datatable.rows.count];
//想象一下我做了一个循环= for i = 0将行放入数据表中
ListofDepartments [i] =新部门()
//进入ListofDepartments [i] .ID并命名
数据表的值
}
}
这是创建这个的好方法吗?

你能给我一个关于可以在
部门类中实现哪些方法的例子(第一个)

非常感谢
问候。
Josema
Hi to all,

actually im a newbie in the OOP and i would like to know if this way of
using clases its a best way (logical, and a good way)

Lets imagine that i have a data base with departments (depid, depname)

if i make the class

public class department
{
private int id;
private string name;

public int ID
{
get{return id;}
set{id=value;}
}
public string Name
{
get{return name;}
set{name=value;}
}
}

like which I want is to create a class for each department i make another
class:

public class departments
{
private department[] ListofDepartments;

public departments()
{
//Imagine that i have a datatable with all the query (select * from
departments)
ListofDepartments=new departament[datatable.rows.count];
//Imagine that i make a loop = for i=0 to rows into the datatable
ListofDepartments[i]=new Department()
//assing into the ListofDepartments[i].ID and Name the values of the
datatable
}
}

Its this a good way to create this?,

Could you put me an example about wich methods could be implemented in the
department class (the first)
Thanks a lot
Regards.
Josema




Hi,

公共类部门
{private int id;
私人字符串名称;

public int ID
{
获取{return id;}
设置{id = value;}
}
公共字符串名称
{
获取{返回名称; }
设置{name = value;}
}
}


到目前为止一切顺利。只有你应该定义一个构造函数,否则你可能

在非初始化值上使用一个get属性(例外)

我想要的是为每个创建一个类部门我再做另一个课程:


Nop,你想要创建一个CLASS类,而不是一个类,它们是

不同的东西!!!

公共类部门
{
私人部门[] ListofDepartments;

公共部门()
{
//想象一下,我有一个包含所有查询的数据表(选择*来自
部门)
ListofDepartments = new departament [datatable.rows.count];
//想象一下,我做了一个循环=对于i = 0到数据行的行
ListofDepartments [i] =新部门()
//对ListofDepartments [i] .ID进行分配并命名
数据表的值
}


这是一个创建这个的好方法吗?


它有效,但IMO它'不是最好的,如果你想要一个确定类型的

的集合,或者换句话说强类型集合你应该从CollectionBase继承
。在MSDN中查看它

你能给我一个关于可以在
部门类(第一个)中实现哪些方法的例子
public class department
{
private int id;
private string name;

public int ID
{
get{return id;}
set{id=value;}
}
public string Name
{
get{return name;}
set{name=value;}
}
}
So far so good. Only that you should define a constructor, otherwise you may
use one get property on an non initializad value ( exception)
like which I want is to create a class for each department i make another
class:
Nop, you want to create an INSTANCE OF A CLASS , not a class, they are
different things !!!
public class departments
{
private department[] ListofDepartments;

public departments()
{
//Imagine that i have a datatable with all the query (select * from
departments)
ListofDepartments=new departament[datatable.rows.count];
//Imagine that i make a loop = for i=0 to rows into the datatable
ListofDepartments[i]=new Department()
//assing into the ListofDepartments[i].ID and Name the values of the
datatable
}
}

Its this a good way to create this?,
It works, but IMO it''s not the best, if you want a collection of a
determined typed, or in other words a Strong Typed Collection you should
inherit from CollectionBase. take a look at it in the MSDN
Could you put me an example about wich methods could be implemented in the
department class (the first)




这取决于你想用它做什么,你要做什么操作

基于部门执行,可能是GetAssociatesList()或主席等等


干杯,

-

Ignacio Machin,
ignacio.machin at dot.state。 fl.us

佛罗里达州交通局



It depends of what you want to do with it, what operations are you gonna to
perform based on Department , maybe a GetAssociatesList() or Chairman , etc

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


好的,我将来看看这个班级


Thnx Nicholas。

Nicholas Paldino [.NET / C#MVP]"写道:
Okay, i will take a look for this Class

Thnx Nicholas.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Josema,

对于你想要做的事情,我认为有更好的方法来做它。首先,类名应该是Department,而不是department。

对于集合类,我将从CollectionBase派生,在
.. NET 2.0中,我将使用List< T> ;上课代表
部门的集合。

然而,我根本不会这样做。最后,我将使用在IDE中设置的类型化数据集并使用它们。它将为数据提供最简单的访问权限,并将这些分组提供给您需要的集合。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

" Josema" <济****** @ ocu.org>在消息中写道
新闻:80 ********************************** @ microsof t.com。 ..
Josema,

For what you are trying to do, I think there are some better ways to do
it. First, the class name should be Department, and not department.

For the collection class, I would derive from CollectionBase, and in
..NET 2.0, I would use the List<T> class to represent the collection of
department.

However, I wouldn''t even do this at all. In the end, I would use typed
data sets set up in the IDE and use those. It would provide the easiest
access for the data, as well as offering that grouping into collections that
you need.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Josema" <Je******@ocu.org> wrote in message
news:80**********************************@microsof t.com...
大家好,

实际上我是OOP中的新手,我想知道这种方式使用clases是一种最好的方式(合乎逻辑的,好的方式)

让我们想象一下我有一个部门的数据库(depid,depname)

如果我上课了
公共类部门
{private int id;
私人字符串名称;

public int ID
{
get {return id; }
设置{id = value;}
}
公共字符串名称
{
获取{返回名称;}
设置{name = value;}
}
}

我想要的就是为每个部门创建一个班级我再做一个班级:

公共班级部门
{私人部门[] ListofDepartments;

公共部门()
//
//想象一下,我有包含所有查询的数据表(选择*来自
部门)
ListofDepartments = new departament [datatable.rows.count];
//想象一下我做一个循环= for i = 0 to行到数据表中的行







/>}

这是创建这个的好方法吗?

你能给我一个关于可以在
部门课程中实现哪些方法的例子(第一个)

非常感谢
问候。
Josema
Hi to all,

actually im a newbie in the OOP and i would like to know if this way of
using clases its a best way (logical, and a good way)

Lets imagine that i have a data base with departments (depid, depname)

if i make the class

public class department
{
private int id;
private string name;

public int ID
{
get{return id;}
set{id=value;}
}
public string Name
{
get{return name;}
set{name=value;}
}
}

like which I want is to create a class for each department i make another
class:

public class departments
{
private department[] ListofDepartments;

public departments()
{
//Imagine that i have a datatable with all the query (select * from
departments)
ListofDepartments=new departament[datatable.rows.count];
//Imagine that i make a loop = for i=0 to rows into the datatable
ListofDepartments[i]=new Department()
//assing into the ListofDepartments[i].ID and Name the values of the
datatable
}
}

Its this a good way to create this?,

Could you put me an example about wich methods could be implemented in the
department class (the first)
Thanks a lot
Regards.
Josema




这篇关于类概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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