SQLite内存数据库操作类
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SQLite;
using System.Text;
using TimedTask.Common; namespace TimedTask.Dal
{
/// <summary>
///
/// </summary>
public sealed class SqliteHelper
{
/// <summary>
/// 数据库链接字符串
/// </summary>
public static string ConnectionString { get; set; }
static SqliteHelper()
{
//数据库文件路径
var filePath = System.Environment.CurrentDirectory + @"\Task.db";
var connStr = string.Format("Data Source={0};failifmissing=false", filePath);//Pooling=true;
ConnectionString = connStr;
} #region AddParameters
/// <summary>
/// 添加参数
/// </summary>
/// <param name="parameters">Hashtable</param>
public static SQLiteParameter[] AddParameters(Hashtable parameters)
{
SQLiteParameter[] param = new SQLiteParameter[parameters.Count];
IDictionaryEnumerator ide = parameters.GetEnumerator();
int i = ;
while (ide.MoveNext())
{
param[i] = AddParameters(ide.Key.ToString(), ide.Value);
i++;
}
return param;
}
/// <summary>
/// 添加参数
/// </summary>
/// <param name="parameterName">参数名</param>
/// <param name="value">参数值</param>
public static SQLiteParameter AddParameters(string parameterName, object value)
{
return AddParameters(parameterName, value, DbType.String, -, ParameterDirection.Input);
}
/// <summary>
/// 创建一个传入参数
/// </summary>
/// <param name="name">参数名称</param>
/// <param name="value">参数值</param>
/// <param name="type">参数类型</param>
/// <param name="size">参数大小</param>
/// <returns></returns>
public static SQLiteParameter AddParameters(string name, object value, DbType type, int size, ParameterDirection direction)
{
SQLiteParameter para = new SQLiteParameter();
para.ParameterName = name;
para.Value = value;
para.DbType = type;
para.Direction = direction;
return para;
}
/// <summary>
/// 创建一个传出参数
/// </summary>
/// <param name="name">参数名称</param>
/// <param name="type">参数类型</param>
/// <param name="size">参数大小</param>
/// <returns></returns>
public static SQLiteParameter AddOutParameter(string name, DbType type = DbType.String, int size = )
{
var para = new SQLiteParameter(name, type, size);
para.Direction = ParameterDirection.Output;
return para;
} /// <summary>
/// 预处理Command对象,数据库链接,事务,需要执行的对象,参数等的初始化
/// </summary>
/// <param name="cmd">Command对象</param>
/// <param name="conn">Connection对象</param>
/// <param name="trans">Transcation对象</param>
/// <param name="useTrans">是否使用事务</param>
/// <param name="cmdType">SQL字符串执行类型</param>
/// <param name="cmdText">SQL Text</param>
/// <param name="cmdParms">SQLiteParameters to use in the command</param>
private static void PrepareCommand(SQLiteCommand cmd, SQLiteConnection conn, ref SQLiteTransaction trans, bool useTrans, CommandType cmdType, string cmdText, params SQLiteParameter[] cmdParms)
{ if (conn.State != ConnectionState.Open)
conn.Open(); cmd.Connection = conn;
cmd.CommandText = cmdText; if (useTrans)
{
trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
cmd.Transaction = trans;
} cmd.CommandType = cmdType; if (cmdParms != null)
{
foreach (SQLiteParameter parm in cmdParms)
cmd.Parameters.Add(parm);
}
} #endregion #region ExecSql /// <summary>
/// 执行数据库操作(新增、更新或删除)
/// </summary>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>所受影响的行数</returns>
public static int ExecSql(string connectionString, string commandText, Hashtable ht)
{
SQLiteParameter[] cmdParms = AddParameters(ht);
if (String.IsNullOrEmpty(connectionString))
connectionString = ConnectionString; return ExecSql(ConnectionString, commandText, CommandType.Text, cmdParms);
} /// <summary>
/// 执行数据库操作(新增、更新或删除)
/// </summary>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>所受影响的行数</returns>
public static int ExecSql(string commandText, Hashtable ht)
{
return ExecSql(null, commandText, ht);
}
/// <summary>
/// 执行数据库操作(新增、更新或删除)
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="cmd">SqlCommand对象</param>
/// <returns>所受影响的行数</returns>
public static int ExecSql(string connectionString, SQLiteCommand cmd)
{
int result = ;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, true, cmd.CommandType, cmd.CommandText);
try
{
result = cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return result;
} /// <summary>
/// 执行数据库操作(新增、更新或删除)
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <returns>所受影响的行数</returns>
public static int ExecSql(string connectionString, string commandText, CommandType commandType)
{
int result = ;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText");
SQLiteCommand cmd = new SQLiteCommand();
using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, true, commandType, commandText);
try
{
result = cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return result;
} /// <summary>
/// 执行数据库操作(新增、更新或删除)
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>所受影响的行数</returns>
public static int ExecSql(string connectionString, string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
{
int result = ;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText"); SQLiteCommand cmd = new SQLiteCommand(); using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, true, commandType, commandText, cmdParms);
try
{
result = cmd.ExecuteNonQuery();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return result;
}
#endregion #region ExecScalar
/// <summary>
/// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="cmd">SqlCommand对象</param>
/// <returns>查询所得的第1行第1列数据</returns>
public static object ExecScalar(string connectionString, SQLiteCommand cmd)
{
object result = ;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, true, cmd.CommandType, cmd.CommandText);
try
{
result = cmd.ExecuteScalar();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return result;
} /// <summary>
/// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <returns>查询所得的第1行第1列数据</returns>
public static object ExecScalar(string connectionString, string commandText, CommandType commandType)
{
object result = ;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText");
SQLiteCommand cmd = new SQLiteCommand();
using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, true, commandType, commandText);
try
{
result = cmd.ExecuteScalar();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return result;
} /// <summary>
/// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>查询所得的第1行第1列数据</returns>
public static object ExecScalar(string connectionString, string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
{
object result = ;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText"); SQLiteCommand cmd = new SQLiteCommand();
using (SQLiteConnection con = new SQLiteConnection(connectionString))
{
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, true, commandType, commandText);
try
{
result = cmd.ExecuteScalar();
trans.Commit();
}
catch (Exception ex)
{
trans.Rollback();
throw ex;
}
}
return result;
} /// <summary>
/// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
/// </summary>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>查询所得的第1行第1列数据</returns>
public static object ExecScalar(string commandText, Hashtable ht)
{
SQLiteParameter[] cmdParms = AddParameters(ht);
return ExecScalar(ConnectionString, commandText, CommandType.Text, cmdParms);
} /// <summary>
/// 执行数据库操作(新增、更新或删除)同时返回执行后查询所得的第1行第1列数据
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="ht">SQL参数对象</param>
/// <returns>查询所得的第1行第1列数据</returns>
public static object ExecScalar(string connectionString, string commandText, Hashtable ht)
{
SQLiteParameter[] cmdParms = AddParameters(ht);
return ExecScalar(connectionString, commandText, CommandType.Text, cmdParms);
}
#endregion #region ExecReader
/// <summary>
/// 执行数据库查询,返回SqlDataReader对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="cmd">SqlCommand对象</param>
/// <returns>SqlDataReader对象</returns>
public static DbDataReader ExecReader(string connectionString, SQLiteCommand cmd)
{
DbDataReader reader = null;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString"); SQLiteConnection con = new SQLiteConnection(connectionString);
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, false, cmd.CommandType, cmd.CommandText);
try
{
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
throw ex;
}
return reader;
} /// <summary>
/// 执行数据库查询,返回SqlDataReader对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <returns>SqlDataReader对象</returns>
public static DbDataReader ExecReader(string connectionString, string commandText, CommandType commandType)
{
DbDataReader reader = null;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText"); SQLiteConnection con = new SQLiteConnection(connectionString);
SQLiteCommand cmd = new SQLiteCommand();
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, false, commandType, commandText);
try
{
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
throw ex;
}
return reader;
} /// <summary>
/// 执行数据库查询,返回SqlDataReader对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>SqlDataReader对象</returns>
public static DbDataReader ExecReader(string connectionString, string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
{
DbDataReader reader = null;
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText"); SQLiteConnection con = new SQLiteConnection(connectionString);
SQLiteCommand cmd = new SQLiteCommand();
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, false, commandType, commandText, cmdParms);
try
{
reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
throw ex;
}
return reader;
}
#endregion #region Query
/// <summary>
/// 执行数据库查询,返回DataSet对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="cmd">SqlCommand对象</param>
/// <returns>DataSet对象</returns>
public static DataTable Query(string connectionString, SQLiteCommand cmd)
{
DataTable dt = new DataTable();
SQLiteConnection con = new SQLiteConnection(connectionString);
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, false, cmd.CommandType, cmd.CommandText);
try
{
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
sda.Fill(dt);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (cmd.Connection != null)
{
if (cmd.Connection.State == ConnectionState.Open)
{
cmd.Connection.Close();
}
}
}
return dt;
} /// <summary>
/// 执行数据库查询,返回DataSet对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <returns>DataSet对象</returns>
public static DataTable Query(string connectionString, string commandText, CommandType commandType)
{
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText");
DataTable dt = new DataTable();
SQLiteConnection con = new SQLiteConnection(connectionString);
SQLiteCommand cmd = new SQLiteCommand();
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, false, commandType, commandText);
try
{
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
sda.Fill(dt);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (con != null)
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
return dt; } /// <summary>
/// 执行数据库查询,返回DataSet对象
/// </summary>
/// <param name="connectionString">连接字符串</param>
/// <param name="commandText">执行语句或存储过程名</param>
/// <param name="commandType">执行类型</param>
/// <param name="cmdParms">SQL参数对象</param>
/// <returns>DataSet对象</returns>
public static DataTable Query(string connectionString, string commandText, CommandType commandType, params SQLiteParameter[] cmdParms)
{
if (connectionString == null || connectionString.Length == )
throw new ArgumentNullException("connectionString");
if (commandText == null || commandText.Length == )
throw new ArgumentNullException("commandText");
DataTable dt = new DataTable();
SQLiteConnection con = new SQLiteConnection(connectionString);
SQLiteCommand cmd = new SQLiteCommand();
SQLiteTransaction trans = null;
PrepareCommand(cmd, con, ref trans, false, commandType, commandText, cmdParms);
try
{
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
sda.Fill(dt);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (con != null)
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
return dt;
} /// <summary>
/// 通用分页查询方法
/// </summary>
/// <param name="connString">连接字符串</param>
/// <param name="tableName">表名</param>
/// <param name="showColumns">查询字段名</param>
/// <param name="where">where条件</param>
/// <param name="orderBy">排序条件</param>
/// <param name="pageSize">每页数据数量</param>
/// <param name="pageIndex">当前页数</param>
/// <param name="recordOut">数据总量</param>
/// <returns>DataTable数据表</returns>
public static DataTable Query(string connectionString, string tableName, string showColumns, string where, string orderBy, int pageSize, int pageIndex, out int recordOut)
{
DataTable dt = new DataTable();
recordOut = Convert.ToInt32(ExecScalar(connectionString, "select count(*) from " + tableName, CommandType.Text));
string pagingTemplate = "select {0} from {1} where {2} order by {3} limit {4} offset {5} ";
int offsetCount = (pageIndex - ) * pageSize;
string commandText = String.Format(pagingTemplate, showColumns, tableName, where, orderBy, pageSize.ToString(), offsetCount.ToString());
using (DbDataReader reader = ExecReader(connectionString, commandText, CommandType.Text))
{
if (reader != null)
{
dt.Load(reader);
}
}
return dt;
}
#endregion #region Exists /// <summary>
/// 记录是否存在
/// </summary>
/// <param name="commandText">sql语句</param>
/// <returns></returns>
public static bool Exists(string commandText)
{
return Exists(null, commandText);
}
/// <summary>
/// 记录是否存在
/// </summary>
/// <param name="connectionString"></param>
/// <param name="commandText">sql语句</param>
/// <returns></returns>
public static bool Exists(string connectionString, string commandText)
{
int result;
if (String.IsNullOrEmpty(connectionString))
connectionString = ConnectionString; object obj = ExecScalar(connectionString, commandText, CommandType.Text);
if (object.Equals(obj, null) || object.Equals(obj, DBNull.Value))
{
result = ;
}
else
{
result = int.Parse(obj.ToString());
}
if (result == )
{
return false;
}
return true;
}
/// <summary>
/// 记录是否存在
/// </summary>
/// <param name="commandText">sql语句</param>
/// <param name="isProc">是否是存储过程</param>
/// <returns></returns>
public static bool Exists(string commandText, Hashtable parameters)
{
return Exists(null, commandText, parameters);
}
/// <summary>
/// 记录是否存在
/// </summary>
/// <param name="commandText">sql语句</param>
/// <param name="isProc">是否是存储过程</param>
/// <returns></returns>
public static bool Exists(string connectionString, string commandText, Hashtable parameters)
{
int result;
if (String.IsNullOrEmpty(connectionString))
connectionString = ConnectionString; object obj = ExecScalar(connectionString, commandText, parameters);
if (object.Equals(obj, null) || object.Equals(obj, DBNull.Value))
{
result = ;
}
else
{
result = int.Parse(obj.ToString());
}
if (result == )
{
return false;
}
return true;
}
#endregion #region DB //你可以在你的程序中约定一个时间间隔执行一次重新组织数据库的操作,节约空间
/// <summary>
/// 收缩数据库
/// </summary>
public void Reset()
{
using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
{
using (SQLiteCommand cmd = new SQLiteCommand())
{
if (conn.State != ConnectionState.Open)
conn.Open(); cmd.Parameters.Clear();
cmd.Connection = conn;
cmd.CommandText = "vacuum";
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = ;
cmd.ExecuteNonQuery();
}
}
}
#endregion
}
}
SQLite内存数据库操作类的更多相关文章
- SQLite C++操作类
为了方便SQLite的使用,封装了一个SQLite的C++类,同时支持ANSI 和UNICODE编码.代码如下: 头文件(SQLite.h) [cpp] view plaincopy /***** ...
- [Android] Sqlite 数据库操作 工具封装类
sqlite 数据库封装类 DatabaseUtil.java(封装的类) package com.jack.androidbase.tools; import android.content.Con ...
- [转]html5 js 访问 sqlite 数据库的操作类
本文转自:http://blog.csdn.net/tsxw24/article/details/7613815 webkit 核心的浏览器提供了 3个 api接口,用于访问本地sqlite数据,但使 ...
- FIREDAC操作SQLITE内存数据库
SQLite不仅可以把数据库放在硬盘上,还可以放在内存中,经测试,同样条件下数据库放在内存中比放在硬盘上插入记录速度快差不多3倍. 但数据库放在内存中时有如下缺陷: 1.断电或程序崩溃后数据库就会消失 ...
- android SQLite使用SQLiteOpenHelper类对数据库进行操作
android SQLite使用SQLiteOpenHelper类对数据库进行操作 原文: http://byandby.iteye.com/blog/835580
- 【原创】System.Data.SQLite内存数据库模式
对于很多嵌入式数据库来说都有对于的内存数据库模式,SQLite也不例外.内存数据库常常用于极速.实时的场景,一个很好的应用的场景是富客户端的缓存数据,一般富客户端的缓存常常需要分为落地和非落地两种,而 ...
- 【知识必备】ezSQL,最好用的数据库操作类,让php操作sql更简单~
最近用php做了点小东东,用上了ezSQL,感觉真的很ez,所以拿来跟大家分享一下~ ezSQL是一个非常好用的PHP数据库操作类.著名的开源博客WordPress的数据库操作就使用了ezSQL的My ...
- Android打造属于自己的数据库操作类。
1.概述 开发Android的同学都知道sdk已经为我们提供了一个SQLiteOpenHelper类来创建和管理SQLite数据库,通过写一个子类去继承它,就可以方便的创建.管理数据库.但是当我们需要 ...
- PHP 数据库操作类:ezSQL
EZSQL类介绍: 下载地址:http://www.jb51.net/codes/26393.htmlezsql是一个小型的快速的数据库操作类,可以让你很容易地用PHP操作各种数据库( MySQL.o ...
随机推荐
- 模拟hadoop-rpc通信
一.RPC服务类 package com.css.rpc.server; import java.io.IOException; import org.apache.hadoop.HadoopIlle ...
- LeetCode—Minimum Size Subarray Sum
题目: Given an array of n positive integers and a positive integer s, find the minimal length of a sub ...
- 【pentaho】【kettle】【Data Integration】试用
要做数据分析,领导让研究一下kettle. 先占个坑. 这里有个3.0的文档: http://wenku.baidu.com/link?url=hvw_cOBIXLXSGvftkGhXQic3CLC7 ...
- django之页面缓存
一 全站缓存(全局缓存) 在settings中配置,主要就是两个中间件,需要注意的就是两个中间件的前后位置 MIDDLEWARE_CLASSES = ( ‘django.middleware.cac ...
- openssl生成证书server.key server.crt
Key是私用秘钥,通常是RSA算法 Csr是证书请求文件,用于申请证书.在制作csr文件时,必须使用自己的私钥来签署申,还可以设定一个密钥. crt是CA认证后的证书文,签署人用自己的key给你签署凭 ...
- ssm之mapper异常 Result Maps collection already contains value for com.ssj.mapper.UserMapper 和 Type interface com.ssj.mapper.UserMapper is already known to the MapperRegistry.
异常一:Result Maps collection already contains value for com.ssj.mapper.XXXMapper 原因分析:XXXmapper.xml文件中 ...
- TensorFlow学习笔记(三)MNIST数字识别问题
一.MNSIT数据处理 MNSIT是一个非常有名的手写体数字识别数据集.包含60000张训练图片,10000张测试图片.每张图片是28X28的数字. TonserFlow提供了一个类来处理 MNSIT ...
- 基于wtforms源码实现自定义form组件
from flask import Flask,Markup,render_template,request,redirect from wtforms.form import Form from w ...
- python全栈开发从入门到放弃之面向对象的三大特性
组合 class Course: def __init__(self,name,period,price): self.name = name self.period = period self.pr ...
- C++ 对象的sizeof问题
需要补充.. 1. 注意虚函数的指针占4个字节.(当然是32位机器) #include <cstdlib> #include <ctime> #include <iost ...