C#的一些技巧

C#编程使用技巧 展开注册表到[HKEY_CURRENT_USER/keyboardlayout/preload]分支,在preload主键下面会有数个以序列号1、2、3、4命名的子键,子键的数目和计算机上安装的输入法一一对应,其中的1、2、3、4代表的是输入法的排列顺序。所以,要调整输入法的顺序,只需修改和1、2、3、4对应的键值即可。例如,想让微软拼音和五笔字型互换位置,就可以在子键2上右击,选择“重命名”选项,先把它改为“w”或其他不存在的名称,接着将子键4改名为2,最后将w改名为4即可。 阅读详情
1.怎样定制VC#DataGrid列标题?
  DataGridTableStyle dgts = new DataGridTableStyle();
  dgts.MappingName = "myTable"; //myTable为要载入数据的DataTable
  
  DataGridTextBoxColumn dgcs = new DataGridTextBoxColumn();
  dgcs.MappingName = "title_id";
  dgcs.HeaderText = "标题ID";
  dgts.GridColumnStyles.Add(dgcs);
  。。。
  dataGrid1.TableStyles.Add(dgts);
  2.检索某个字段为空的所有记录的条件语句怎么写?
  ...where col_name is null
  3.如何在c# Winform应用中接收回车键输入?
  设一下form的AcceptButton.
  4.比如Oracle中的NUMBER(15),在Sql Server中应是什么?
  NUMBER(15):用numeric,精度15试试。
  5.sql server的应用like语句的存储过程怎样写?
  select * from mytable where haoma like ‘%’ + @hao + ‘%’
  6.vc# winform中如何让textBox接受回车键消息(假没没有按钮的情况下)?
  private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  {
   if(e.KeyChar != (char)13)
   return;
   else
   //do something;
  }
  7.为什么(Int32)cmd.ExecuteScalar()赋值给Int32变量时提示转换无效?
  Int32.Parse(cmd.ExecuteScalar().ToString());
  8.DataSource为子表的DataGrid里怎样增加一个列以显示母表中的某个字段?
  在子表里手动添加一个列。
  DataColumn dc = new DataColumn("newCol", Type.GetType("System.String"));
  dc.Expression = "Parent.parentColumnName";
  dt.Columns.Add(dc); //dt为子表
  9.怎样使DataGrid显示DataTable中某列的数据时只显示某一部分?
  select ..., SUBSTR(string, start_index, end_index) as ***, *** from ***
  10.如何让winform的combobox只能选不能输入?
  DropDownStyle 属性确定用户能否在文本部分中输入新值以及列表部分是否总显示。
  值:
  DropDown --- 文本部分可编辑。用户必须单击箭头按钮来显示列表部分。
  DropDownList --- 用户不能直接编辑文本部分。用户必须单击箭头按钮来显示列表部分。
  Simple --- 文本部分可编辑。列表部分总可见。
  11.怎样使winform的DataGrid里显示的日期只显示年月日部分,去掉时间?
  sql语句里加上to_date(日期字段,'yyyy-mm-dd')
  12.怎样把数据库表的二个列合并成一个列Fill进DataSet里?
  dcChehao = new DataColumn("newColumnName", typeof(string));
  dcChehao.Expression = "columnName1+columnName2";
  dt.Columns.Add(dcChehao);
  Oracle:
  select col1||col2 from table
  sql server:
  select col1+col2 from table
  13.如何从合并后的字段里提取出括号内的文字作为DataGrid或其它绑定控件的显示内容?即把合并后的字段内容里的左括号(和右括号)之间的文字提取出来。
  Select COL1,COL2, case
  when COL3 like ‘%(%’ THEN substr(COL3, INSTR(COL3, ‘(’ )+1, INSTR(COL3,‘)’)-INSTR(COL3,‘(’)-1)
  end as COL3
  from MY_TABLE
  14.当用鼠标滚轮浏览DataGrid数据超过一定范围DataGrid会失去焦点。怎样解决?
  this.dataGrid1.MouseWheel+=new MouseEventHandler(dataGrid1_MouseWheel);
  private void dataGrid1_MouseWheel(object sender, MouseEventArgs e)
  {
   this.dataGrid1.Select();
  }
  15.怎样把键盘输入的‘+’符号变成‘A’?
  textBox的KeyPress事件中
  if(e.KeyChar == '+')
  {
   SendKeys.Send("A");
   e.Handled = true;
  }
  16.怎样使Winform启动时直接最大化?
  this.WindowState = FormWindowState.Maximized;
  17.c#怎样获取当前日期及时间,在sql语句里又是什么?
  c#: DateTime.Now
  sql server: GetDate()
  18.怎样访问winform DataGrid的某一行某一列,或每一行每一列?
  dataGrid[row,col]
  19.怎样为DataTable进行汇总,比如DataTable的某列值‘延吉'的列为多少?
  dt.Select("城市='延吉'").Length;
  20.DataGrid数据导出到Excel后0212等会变成212。怎样使它导出后继续显示为0212?
  range.NumberFormat = "0000";
  21.
  ① 怎样把DataGrid的数据导出到Excel以供打印?
  ② 之前已经为DataGrid设置了TableStyle,即自定义了列标题和要显示的列,如果想以自定义的视图导出数据该怎么办?
  ③ 把数据导出到Excel后,怎样为它设置边框啊?
  ④ 怎样使从DataGrid导出到Excel的某个列居中对齐?
  ⑤ 数据从DataGrid导出到Excel后,怎样使标题行在打印时出现在每一页?
  ⑥ DataGrid数据导出到Excel后打印时每一页显示’当前页/共几页’,怎样实现?
  ①
  private void button1_Click(object sender, System.EventArgs e)
  {
   int row_index, col_index;
  
   row_index = 1;
   col_index = 1;
  
   Excel.ApplicationClass excel = new Excel.ApplicationClass();
   excel.Workbooks.Add(true);
  
   DataTable dt = ds.Tables["table"];
  
   foreach(DataColumn dcHeader in dt.Columns)
   excel.Cells[row_index, col_index++] = dcHeader.ColumnName;
  
   foreach(DataRow dr in dt.Rows)
   {
   col_index = 0;
   foreach(DataColumn dc in dt.Columns)
   {
   excel.Cells[row_index+1, col_index+1] = dr[dc];
   col_index++;
   }
   row_index++;
   }
   excel.Visible = true;
  
   }
  
  private void Form1_Load(object sender, System.EventArgs e)
  {
  SqlConnection conn = new SqlConnection("server=tao;uid=sa;pwd=;database=pubs");
  conn.Open();
  
  SqlDataAdapter da = new SqlDataAdapter("select * from authors", conn);
  ds = new DataSet();
  da.Fill(ds, "table");
  
  dataGrid1.DataSource = ds;
  dataGrid1.DataMember = "table";
  }
  ②dataGrid1.TableStyles[0].GridColumnStyles[index].HeaderText;//index可以从0~dataGrid1.TableStyles[0].GridColumnStyles.Count遍历。
  ③ Excel.Range range;
  range=worksheet.get_Range(worksheet.Cells[1,1],xSt.Cells[ds.Tables[0].Rows.Count+1,ds.Tables[0].Columns.Count]);
  
  range.BorderAround(Excel.XlLineStyle.xlContinuous,Excel.XlBorderWeight.xlThin,Excel.XlColorIndex.xlColorIndexAutomatic,null);
  
  range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;
  range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle =Excel.XlLineStyle.xlContinuous;
  range.Borders[Excel.XlBordersIndex.xlInsideHorizontal].Weight =Excel.XlBorderWeight.xlThin;
  
  range.Borders[Excel.XlBordersIndex.xlInsideVertical].ColorIndex =Excel.XlColorIndex.xlColorIndexAutomatic;
  range.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.XlLineStyle.xlContinuous;
  range.Borders[Excel.XlBordersIndex.xlInsideVertical].Weight = Excel.XlBorderWeight.xlThin;
  ④ range.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
  ⑤ worksheet.PageSetup.PrintTitleRows = "$1:$1";
  ⑥ worksheet.PageSetup.CenterFooter = "第&P页 / 共&N页";
  22.当把DataGrid的Cell内容赋值到Excel的过程中想在DataGrid的CaptionText上显示进度,但不显示。WHY?
  ...
  dataGrid1.CaptionText = "正在导出:" + (row + 1) + "/" + row_cnt;
  System.Windows.Forms.Application.DoEvents();
  ...
  
  处理当前在消息队列中的所有Windows消息。
  
  当运行Windows窗体时,它将创建新窗体,然后该窗体等待处理事件。该窗体在每次处理事件时,均将处理与该事件关联的所有代码。所有其他事件在队列中等待。在代码处理事件时,应用程序并不响应。如果在代码中调用DoEvents,则应用程序可以处理其他事件。
  如果从代码中移除DoEvents,那么在按钮的单机事件处理程序执行结束以前,窗体不会重新绘制。通常在循环中使用该方法来处理消息。
  23.怎样从Flash调用外部程序,如一个C#编译后生成的.exe?
  fscommand("exec", "应用程序.exe");
  ① 必须把flash发布为.exe
  ② 必须在flash生成的.exe文件所在目录建一个名为fscommand的子目录,并把要调用的可执行程序拷贝到那里。
  24.有没有办法用代码控制DataGrid的上下、左右的滚动?
  dataGrid1.Select();
  SendKeys.Send("{PGUP}");
  SendKeys.Send("{PGDN}");
  SendKeys.Send("{^{LEFT}"); // Ctrl+左方向键
  SendKeys.Send("{^{RIGHT}"); // Ctrl+右方向键
  25.怎样使两个DataGrid绑定两个主从关系的表?
  DataGrid1.DataSource = ds;
  DataGrid1.DataMember = "母表";
  ...
  DataGrid2.DataSouce = ds;
  DataGrid2.DataMember = "母表.关系名";
  26.assembly的版本号怎样才能自动生成?特别是在Console下没有通过VStudio环境编写程序时。
  关键是AssemblyInfo.cs里的[assembly: AssemblyVersion("1.0.*")],命令行编译时包含AssemblyInfo.cs
  27.怎样建立一个Shared Assembly?
  用sn.exe生成一个Strong Name:keyfile.sn,放在源程序目录下
  在项目的AssemblyInfo.cs里[assembly: AssemblyKeyFile("..//..//keyfile.sn")]
  生成dll后,用gacutil /i myDll.dll放进Global Assembly Cach.
  28.在Oracle里如何取得某字段第一个字母为大写英文A~Z之间的记录?
  select * from table where ascii(substr(字段,1,1)) between ascii('A') and ascii('Z')
  29.怎样取得当前Assembly的版本号?
  Process current = Process.GetCurrentProcess();
  FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(current.MainModule.FileName);
  Console.WriteLine(myFileVersionInfo.FileVersion);
  30.怎样制作一个简单的winform安装程序?
  ① 建一个WinForm应用程序,最最简单的那种。运行。
  ② 添加新项目->安装和部署项目,‘模板’选择‘安装向导’。
  ③ 连续二个‘下一步’,在‘选择包括的项目输出’步骤打勾‘主输出来自’,连续两个‘下一步’,‘完成’。
  ④ 生成。
  ⑤ 到项目目录下找到Setup.exe(还有一个.msi和.ini文件),执行。
  31.怎样通过winform安装程序在Sql Server数据库上建表?
  ① [项目]—[添加新项]
  类别:代码;模板:安装程序类。
  名称:MyInstaller.cs
  ② 在SQL Server建立一个表,再[所有任务]—[生成SQL脚本]。
  生成类似如下脚本(注意:把所有GO语句去掉):
  if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MyTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
  drop table [dbo].[MyTable]
  
  Create TABLE [dbo].[MyTable] (
   [ID] [int] NOT NULL ,
   [NAME] [nchar] (4) COLLATE Chinese_PRC_CI_AS NOT NULL
  ) ON [PRIMARY]
  
  
  Alter TABLE [dbo].[MyTable] WITH NOCHECK ADD
   CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED
   (
   [ID]
   ) ON [PRIMARY]
  ③ [项目]—[添加现有项]。mytable.sql—[生成操作]-[嵌入的资源]。
  ④ 将MyInstaller.cs切换到代码视图,添加下列代码:
  先增加:
  using System.Reflection;
  using System.IO;
  然后:
  private string GetSql(string Name)
  {
    try
    {
      Assembly Asm = Assembly.GetExecutingAssembly();
      Stream strm = Asm.GetManifestResourceStream(Asm.GetName().Name + "." + Name);
      StreamReader reader = new StreamReader(strm);
      return reader.ReadToEnd();
    }
    catch (Exception ex)
    {
      Console.Write("In GetSql:"+ex.Message);
      throw ex;
    }
  }
  
  private void ExecuteSql(string DataBaseName,string Sql)
  {
  System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection();
  sqlConn.ConnectionString = "server=myserver;uid=sa;password=;database=master";
  System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand(Sql,sqlConn);
  
  Command.Connection.Open();
  Command.Connection.ChangeDatabase(DataBaseName);
  try
  {
  Command.ExecuteNonQuery();
  }
  finally
  {
  Command.Connection.Close();
  }
  }
  protected void AddDBTable(string strDBName)
  {
   try
   {
   ExecuteSql("master","create DATABASE "+ strDBName);
   ExecuteSql(strDBName,GetSql("mytable.sql"));
   }
   catch(Exception ex)
   {
   Console.Write("In exception handler :"+ex.Message);
   }
  }
  
  public override void Install(System.Collections.IDictionary stateSaver)
  {
   base.Install(stateSaver);
   AddDBTable("MyDB"); //建一个名为MyDB的DataBase
  }
  ⑤ [添加新项目]—[项目类型:安装和部署项目]—[模板:安装项目]—[名称:MySetup]。
  ⑥ [应用程序文件夹]—[添加]—[项目输出]—[主输出]。
  ⑦ 解决方案资源管理器—右键—[安装项目(MySetup)]—[视图]—[自定义操作]。[安装]—[添加自定义操作]—[双击:应用程序文件夹]的[主输出来自***(活动)]。
  32.怎样用TreeView显示父子关系的数据库表(winform)?
  三个表a1,a2,a3, a1为a2看母表,a2为a3的母表。
  a1: id, name
  a2: id, parent_id, name
  a3: id, parent_id, name
  用三个DataAdapter把三个表各自Fill进DataSet的三个表。
  用DataRelation设置好三个表之间的关系。
  
  foreach(DataRow drA1 in ds.Tables["a1"].Rows)
  {
   tn1 = new TreeNode(drA1["name"].ToString());
   treeView1.Nodes.Add(tn1);
   foreach(DataRow drA2 in drA1.GetChildRows("a1a2"))
   {
    tn2 = new TreeNode(drA2["name"].ToString());
    tn1.Nodes.Add(tn2);
    foreach(DataRow drA3 in drA2.GetChildRows("a2a3"))
    {
     tn3 = new TreeNode(drA3["name"].ToString());
     tn2.Nodes.Add(tn3);
    }
   }
  }
  33.怎样从一个form传递数据到另一个form?
  假设Form2的数据要传到Form1的TextBox。
  在Form2:
  // Define delegate
  public delegate void SendData(object sender);
  // Create instance
  public SendData sendData;
  在Form2的按钮单击事件或其它事件代码中:
  if(sendData != null)
  {
   sendData(txtBoxAtForm2);
  }
  this.Close(); //关闭Form2
  在Form1的弹出Form2的代码中:
  Form2 form2 = new Form2();
  form2.sendData = new Form2.SendData(MyFunction);
  form2.ShowDialog();
  ====================
  private void MyFunction(object sender)
  {
   textBox1.Text = ((TextBox)sender).Text;
  }  
C#高级编程技巧与应用实践 本文介绍了C#编程语言的一些高级编程技巧和应用实践,包括委托和事件、泛型、LINQ查询、异步编程和特性等。掌握这些技巧和实践,可以帮助我们提高编程效率,写出更高质量的代码。委托是一种用于封装方法的类型,可以将方法作为参数传递给其他方法。通过委托和事件,我们可以实现松耦合的设计,提高代码的可维护性和扩展性。本文将介绍C#编程语言的一些高级编程技巧和应用实践,帮助读者提高编程效率,写出更高质量的代码。除了使用.NET Framework提供的泛型集合外,我们还可以自定义泛型类和方法。 阅读详情

相关推荐

DataGrid自定义列标题

DataGrid自定义列标题 DataGrid自定义列标题 DataGrid自定义列标题 DataGrid自定义列标题 DataGrid自定义列标题

WPF中, DataGrid表格设置标题Header文字大小和行高

记录DataGrid当中设置标题文字大小和行高的方法

m0_50214533的博客 6495

198个经典C#源码-之01-窗体技巧.rar

QQ窗体 窗体的浮动及隐藏 窗体换肤 磁性窗体的设计 仿XP系统的任务栏菜单 滚动字幕 获取文件类型 获取文件目录 焦点变色 手动改变自制窗体的大小 鼠标穿透 鼠标穿透窗体 无边框窗体 限制窗体大小 向窗体中拖放图片并显示 隐藏工具箱 用树型列表动态显示菜单 自定义窗体的最大化、最小化和关闭按钮 自定义屏保

winform中DataGridView行标题和列标题颜色设置

1.点击DataGridView,在右侧的属性面板中点击RowHeaderDefaultCellStyle,在这里可以设置行标题和列标题的颜色,显示格式等;注释:在设置完成之后要把EnableHeaderVisualStyle这个属性设置为false,这样前面设置的行标题和列标题的属性才会生效;2.同行标题的设置。

weixin_43786608的博客 2606

Unity中USD场景导入与工业级协作实战指南

USD(Universal Scene Description)是一种面向复杂三维场景的结构化数据模型,其核心在于分层描述、变体管理与非破坏性组合,本质是支持多团队并行协作的场景协议。它不同于传统模型格式,强调运行时可编辑性与版本可控性,技术价值体现在跨软件资产一致性、零拷贝动态叠加及内存中实时合成。典型应用场景包括建筑BIM实时漫游、汽车多配置仿真、影视级灯光材质协同等工业管线。在Unity中,USD已深度集成于URP/HDRP管线,通过原生USD Importer、Runtime与Exporter三组件

weixin_32073537的博客 301

QT6实现USB摄像头接入显示与抓拍功能实现

QT实现USB摄像头接入显示 一、UVC协议简介 UVC全称是USB Video Class(USB视频类),是一种标准化的USB视频设备通信协议,它定义了摄像头与主机之间的数据传输协议和格式。 UVC协议的出现,解决了摄像头厂商之间互不兼容,以及摄像头应用开发与平台之间的散乱问题。 UVC标准是由USB-IF主导制定的,目前最新的版本是UVC 1.5,UVC的缺省设置类容易实现,不需要额外的驱动程序。

热土程序园,利他愉己~ 3416

C#学习常用类--DataRow类

DataRow类:表示行中的数据 DataTable。命名空间: System.Data程序集: System.Data(位于 System.Data.dll)继承层次结构System.ObjectSystem.Data.DataRow语法:publicclassDataRow构造函数名称说明DataRow(DataR...

weixin_33841503的博客 2221

《大数据最全面试题-Offer直通车》目录

做好这些不用担心试用期不通过:程序员入职新公司如何快速上手项目本人遇到大数据面试题和参考答案(超过1万字精华版)大数据面试英文自我介绍参考(万字长文)大数据运维应用场景面试题汇总及参考答案(持续更新)万字数据仓库面试题及参考答案数据仓库数据质量监控和处理方法最佳实践数据仓库建模方法万字详解Doris的3种数据模型详解和数据仓库每一层的模型选用大数据面试临阵磨枪不知看什么?看这份心理就有底了-大数据常用技术栈常见面试100道题最全Hive面试题2024年(2万字详解)Elasticsearch 面试题及参考答

大模型大数据攻城狮的专栏 2643

c# 对DataTable各种常用操作的源代码DataTableHelper

using System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Data;  using System.Collections;  using System.ComponentModel;  namespace Soft.Lib  {   

shan1774965666的专栏 1677

Centos 7 Linux 安装 JDK 8:下载、安装、配置环境变量、验证

本文详细介绍了在 CentOS 7 系统上手动安装 JDK 8 的完整流程,包括环境准备、JDK 安装包下载与上传、解压安装、配置全局环境变量,以及最终的验证步骤。适用于使用 VMware 虚拟机、云服务器或物理机的 CentOS 7 用户,操作清晰、步骤完整,帮助开发者快速搭建 Java 开发环境。

寒水馨 · 轻量级技术文档 · hanshuixin.org 2582

2024顶级提示工程工具:提升效率的12个神器

LlamaIndex虽然本身不是直接的提示词编辑工具,但其整个设计都围绕着如何有效地将外部知识融入LLM的提示词。它提供了结构化的方式来管理“上下文窗口”——即哪些私有数据应该被包含在提示词中。通过优化索引结构和检索策略,可以确保提示词中包含最相关、最高质量的上下文信息,从而大幅提升LLM基于私有数据回答问题的准确性和相关性。同时,LlamaIndex允许开发者针对不同的查询类型和数据特点定制提示词模板,这使得提示词的复用和优化更加系统化。

AIGC应用创新大全的博客 1098

WPF的DataGrid设置标题头

上述示例中,BorderThickness属性设置为"0,0,0,2"表示只显示底部的分割线,厚度为2个像素;在给定的代码中,列头的内容将水平居中对齐,背景和前景颜色分别为白色和黑色,边框厚度为 1 像素,边框颜色为浅灰色。要设置DataGrid标题头的分割线、背景色和前景色等属性,您可以使用DataGrid的样式和模板来自定义标题头的外观。上述示例中,Foreground属性设置为"#FFFFFF"表示标题头的前景色(文字颜色)为白色。:设置列头的前景颜色(文字颜色)为黑色 (#000000)。

ultramand的博客,重生之我在cad上二次开发猛猛敲C#代码~ 3418

ABAP CDS 实体权限控制,从 DCL 到 PFCG 的完整运行逻辑

本文探讨了SAP S/4HANA开发中CDS View的权限控制机制。核心观点如下: CDS access control通过DCL语言实现数据实例级权限控制,而非替代传统PFCG权限体系,二者形成互补关系:PFCG控制功能入口权限,DCL控制数据可见性。 DDL定义数据结构,DCL定义访问规则。DCL通过角色映射将数据字段与PFCG授权对象关联,运行时自动将权限条件注入SQL查询,实现数据过滤。 访问控制行为特点: 无DCL role不会默认拒绝访问 权限检查通过减少结果集而非抛出错误实现 需配合@Acc

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 101

10 个 C#常用高级技巧

概述:作为 C# 开发人员,学习更高级的技术可以帮助您编写更简洁、更高效和更具创新性的代码。在本文中,我们将探讨一些十个高级 C# 技巧,这些技巧是为想要突破 C# 极限的更有经验的开发人员量身定制的。这些技巧可以提高代码的性能、可读性和可维护性。1. 利用元组获取多个返回值传统上,要从方法返回多个值,开发人员必须使用参数并创建自定义类或结构。但是,C# 7 引入了元组,这使得这样做更容易、更易读。}此方法简化了对多个返回值的处理。

2401_82584055的博客 2151

【RV1126/RV1109学习笔记】#基础篇#(2)基础入门使用

一、调试方式 1、串口调试 2、ADB调试 3、网络调试 二、基础外设使用 音频使用(aplay,arecord,amixer) 三、WIFI连接 四、屏幕背光控制

丨晋丨 1858

IPGUARD客户端与应用程序冲突

客户端与应用程序冲突 症状 安装客户端之后,客户端的某些程序无法运行或使用过程中出现异常,卸载客户端后恢复正常。 原因分析 可能是客户端的某些功能与应用程序发生冲突导致。 解决方法 当出现这样的情况时,可以按照以下步骤确认。 步骤1:屏蔽主动注入 在客户端配置策略中,增加配置策略hookapi_disinj,值为1;待策略同步到客户端后,重启客户端确认问题是否解决。如果解决,则转到...

IP-Guard专栏 1411

学习C#的技巧

寻找如何C#技巧

wanglixinga的专栏 216

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

深入理解C#:15个实用C#编程技巧总结

C#是一种安全的、稳定的、简单的、优雅的,由C和C++衍生出来的面向对象的编程语言。它在继承C和C++强大功能的同时去掉了一些它们的复杂特性(例如没有宏以及不允许多重继承)。 同时。C#综合了VB简单的可视化操作和C++的高运行效率,以其强大的操作能力、优雅的语法风格、创新的语言特性和便捷的面向组件编程的支持成为.NET开发的首选语言。 本文整理了C#开发和使用过程中的15个小技巧,希望能对大...

DLQFHL的博客 2284

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

C# 的一些小技巧

C# 的一些小技巧 1)快捷地输入程序框架 (1)cw + tab键 => Console.WriteLine(); (2)for + tab键 => for 的基本框架 (3)if + tab键 => if 的基本框架 (4)ctor + tab键 => 构造器的基本框架 (5)prop + tab键 => 属性的基本框架 2)快捷键 (1)Ctrl + K,C => 注释选中内容 (2)Ctrl + K,U => 取消注释选中内容 (3)Ctrl +

qq_48015123的博客 308

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

七个C#编程的小技巧

一、最小化窗口 点击“X”或“Alt F4”时,最小化窗口, 如: protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x0112; const int SC_CLOSE = 0xF060; if (m.Msg == WM_SYSCOMMAND &amp;&amp; (int) m.W...

weixin_33725126的博客 658

C# 小技巧

我搞C#编程有些时候了,现在把自己学会的一些技巧告诉大家。这里我们假定你使用的是Visual Studio .net 20031.#region...#endregion这个不要说了,相信很多人都在用(如果还不知道的话自己在一段代码前后加这两句,看看什么效果)2.@这个符号干什么用的呢?看看一下两句:System.Console.WriteLine("C://Windows//Explor

enginetanmary的专栏 550

C#注释的技巧

正确地注释代码是编写高质量代码的一个重要部分。XML注释是C#中最常用的注释方式之一,它可以帮助您编写更清晰和易于阅读的代码。还有一些技巧需要掌握,例如保持注释简洁、编写自己的标准注释、重要块前加注释,以及使用批注等。遵循这些技巧,可以让您的代码更容易维护,更加易于理解,从而编写出高质量的代码。

jiawei31191的博客 2299

C#常用技巧

C#常用技巧导读: 1. 打开新的窗口并传送参数:   传送参数: response.write("window.open(’*.aspx?id="+this.DropDownList1.SelectIndex+"&id1="+...+"’)</script>")   接收参数: stringa = Request.QueryString("id"); stringb = Reques

lilm36的专栏 521

C#小技巧总结

学习和应用C#过程中积累的一些小技巧,学到一点就在上面加一点 1:C#控制台程序,不想显示dos窗口。方法:在解决方案资源管理器中,选中工程,右键,属性,输出类型选为“windows 应用程序” 即可。

qq_25718147的博客 358
上一篇: 利用vs.net快速开发windows服务(c#)
下一篇: Ajax.NET Professional for Microsoft.NET Framework 1.1
goding
博客等级 码龄23年 20粉丝 38原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值