OOP新手 [英] OOP newbie

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

问题描述

大家好,


我正在使用C#2.0。我想生成这样的代码:

展开 | 选择 | Wrap | 行号

解决方案

您是否想要获取与此匹配的汽车数量作为对数据库的查询?如果你有一个汽车数据库,有多少是汽车(不是卡车)而是红色(而不是蓝色)


数据库操作方法第1部分和第2部分
数据库教程第1部分
数据库教程第2部分


如果您使用的是C#3.0,那么使用LINQ会有一种非常简单的方法,但是在2.0中没有什么可以完全按照你的建议去做。


假设我们这里没有谈论数据库的东西,那么OOP的做法是创建具有适当属性和方法的类来做你想做的事。


这是你想要做的示例程序。我认为它应该在C#2.0中运行。这需要添加对System.Drawing的引用。

展开 | 选择 | Wrap | 行号


顺便说一下,这是多少钱如果你可以使用C#3.0更简单,更简单:

展开 | 选择 | Wrap | 行号

Hi All,

I''m using C# 2.0. I want to produce code like this:

Expand|Select|Wrap|Line Numbers

解决方案

Are you trying to get the number of cars that match this as a query to a database? If you had a database of cars, how many are a ''car'' (not ''truck'') and are ''red'' (instead of ''blue'')

Database How-to parts 1 and 2
Database tutorial Part 1
Database tutorial Part 2


If you were using C# 3.0, there would be a very easy way to do this with LINQ, but in 2.0 there is nothing to do exactly what you''re suggesting here.

Assuming we''re not talking about database stuff here, the OOP way of doing this is to create classes with the proper Properties and Methods to do what you want.

Here''s a sample program of what you want to do. I think it should work in C# 2.0. This requires adding a reference to System.Drawing.

Expand|Select|Wrap|Line Numbers


This, by the way, is how much easier and simpler it is if you can work with C# 3.0:

Expand|Select|Wrap|Line Numbers


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

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