C#中通过反射方法获取控件类型和名称
这个方法是简单的也是神奇的。
有木有想过,将自己项目中的所有类型,包括自定义类型的命名空间和名称全部获取出来?
有木有想过,有一种简便的方法可以自动化管理项目中的控件和窗体?
有木有想过...
首先,要敢想、要敢尝试。
通过以下方法,进行简单变换,是可以做到本程序控制本项目的窗体和控件。
以下方法简单了,就不一一说明了,如果你觉得有用,全部复制了编译一下,看看就明白是怎么反射了。
当然懂得大大们看到我有不足之处,请不要谩骂了,我脸皮薄,被你们骂骂就泄气了,技术有限,请大大们不吝赐教。
基础方法
通过反射获取项目中所有类型(重点)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace BackgroundManager.Func
{
public class GetAssemblyClass
{
static Type[] _assemblyArray;
readonly static Object lockObject = new Object(); public Type[] GetAssembly()
{
if (_assemblyArray == null)
{
lock (lockObject)
{
_assemblyArray = Assembly.GetExecutingAssembly().GetTypes();
}
}
return _assemblyArray;
} public Type[] GetFormAssembly()
{
Type[] assemblyArray = GetAssembly();
string allType = typeof(Form).FullName;
string mainType = typeof(frmMain).FullName;
return Array.FindAll(assemblyArray, delegate(Type type)
{
return (type.BaseType.FullName == allType && type.FullName != mainType);
});
} public Type[] GetUserCtlAssembly()
{
Type[] assemblyArray = GetAssembly();
string allType = typeof(UserControl).FullName;
string mainType = typeof(frmMain).FullName;
return Array.FindAll(assemblyArray, delegate(Type type)
{
return (type.BaseType.FullName == allType && type.FullName != mainType);
});
}
}
}
GetAssemblyClass
图像相关帮助类
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Win32; namespace BackgroundManager.Func
{
public class SystemIconHelper
{
[DllImport("shell32.dll")]
public static extern uint ExtractIconEx(string lpszFile, int nIconIndex, int[] phiconLarge,
int[] phiconSmall, uint nIcons); [DllImport("gdi32.dll")]
private static extern bool DeleteObject(IntPtr hObject); public static Dictionary<String, Icon> IconList = new Dictionary<String, Icon>(); /// <summary>
/// Image转换为Icon
/// </summary>
/// <param name="orgImg"></param>
/// <returns></returns>
public static Icon ImageToIcon(Image orgImg)
{
var bmp = new Bitmap(orgImg);
IntPtr h = bmp.GetHicon();
Icon icon = Icon.FromHandle(h);
// 释放IntPtr
DeleteObject(h);
return icon;
} /// <summary>
/// Image 转化为 字节流
/// </summary>
/// <param name="image"></param>
/// <param name="Format"></param>
/// <returns></returns>
public static byte[] ImageToByteArray(Image image, ImageFormat Format)
{
var ms = new MemoryStream();
image.Save(ms, ImageFormat.Png);
return ms.ToArray();
} /// <summary>
/// 字节流 转化为 Image
/// </summary>
/// <param name="btArray"></param>
/// <returns></returns>
public static Image ImageFromByteArray(byte[] btArray)
{
var ms = new MemoryStream(btArray);
Image returnImage = Image.FromStream(ms);
return returnImage;
} /// <summary>
/// 获取文件内容的类型
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string GetContentType(string fileName)
{
string contentType = "application/octetstream";
try
{
string ext = Path.GetExtension(fileName).ToLower();
RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey(ext);
if (registryKey != null && registryKey.GetValue("Content Type") != null)
contentType = registryKey.GetValue("Content Type").ToString();
}
catch (Exception)
{ }
return contentType;
} /// <summary>
/// 根据文件的类型获取 Icon
/// </summary>
/// <param name="sFileExt"></param>
/// <returns></returns>
public static Icon GetIconByFileType(String sFileExt)
{
string sProg =
Registry.ClassesRoot.OpenSubKey(Registry.ClassesRoot.OpenSubKey(sFileExt).GetValue(String.Empty).ToString())
.OpenSubKey("shell")
.OpenSubKey("open")
.OpenSubKey("command")
.GetValue(String.Empty)
.ToString();
sProg = sProg.Substring(, ) == Convert.ToChar().ToString()
? sProg.Substring(, sProg.IndexOf(Convert.ToChar(), ) - )
: sProg.Substring(, sProg.IndexOf(" ", ));
sProg = sProg.Replace("%1", String.Empty);
Icon oIcon = Icon.ExtractAssociatedIcon(sProg);
return oIcon;
} /// <summary>
/// 根据文件名获得图片数组下标
/// </summary>
/// <param name="fileName"></param>
/// <param name="isLarge"></param>
/// <returns></returns>
public static Icon GetIconByFileName(String fileName, bool isLarge)
{
String GetIcon = new FileInfo(fileName).Extension;
if (IconList.ContainsKey(GetIcon))
{
return IconList[GetIcon];
} Icon mIcon = GetIconByFileType(GetIcon, isLarge);
if (mIcon != null)
{
IconList.Add("GetIcon", mIcon);
return mIcon;
} return null;
} /// <summary>
/// 给出文件扩展名(.*),返回相应图标
/// 若不以"."开头则返回文件夹的图标。
/// </summary>
/// <param name="fileType"></param>
/// <param name="isLarge"></param>
/// <returns></returns>
public static Icon GetIconByFileType(string fileType, bool isLarge)
{
if (!string.IsNullOrEmpty(fileType))
{
string regIconString = null;
//默认指定为文件夹图标
string systemDirectory = Environment.SystemDirectory + "\\shell32.dll,3"; if (fileType[] == '.')
{
//读系统注册表中文件类型信息
RegistryKey regVersion = Registry.ClassesRoot.OpenSubKey(fileType, true);
if (regVersion != null)
{
string regFileType = regVersion.GetValue(String.Empty) as String;
regVersion.Close();
regVersion = Registry.ClassesRoot.OpenSubKey(regFileType + @"\DefaultIcon", true);
if (regVersion != null)
{
regIconString = regVersion.GetValue(String.Empty) as String;
regVersion.Close();
}
}
if (regIconString == null)
{
//没有读取到文件类型注册信息,指定为未知文件类型的图标
regIconString = systemDirectory + "shell32.dll,0";
}
}
String[] fileIcon = regIconString.Split(new[] { ',' });
if (fileIcon.Length != )
{
//系统注册表中注册的标图不能直接提取,则返回可执行文件的通用图标
fileIcon = new[] { systemDirectory + "shell32.dll", "" };
}
Icon resultIcon = null;
try
{
//调用API方法读取图标
var phiconLarge = new int[];
var phiconSmall = new int[];
ExtractIconEx(fileIcon[], Int32.Parse(fileIcon[]), phiconLarge, phiconSmall, );
var IconHnd = new IntPtr(isLarge ? phiconLarge[] : phiconSmall[]);
resultIcon = Icon.FromHandle(IconHnd);
}
catch
{
try
{
//第二方案
resultIcon = GetIconByFileType(fileType);
}
catch
{
//默认方案
regIconString = systemDirectory + "shell32.dll,0";
fileIcon = regIconString.Split(new[] { ',' });
resultIcon = null;
//调用API方法读取图标
var phiconLarge = new int[];
var phiconSmall = new int[];
ExtractIconEx(fileIcon[], Int32.Parse(fileIcon[]), phiconLarge, phiconSmall, );
var IconHnd = new IntPtr(isLarge ? phiconLarge[] : phiconSmall[]);
resultIcon = Icon.FromHandle(IconHnd);
}
}
return resultIcon;
} return null;
} }
}
SystemIconHelper
自定义属性的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace BackgroundManager
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class MyAttribute : Attribute
{
private string _name = "";
private string _display = "";
private string _value = ""; public MyAttribute(string name, string value, string display)
{
_name = name;
_value = value;
_display = display;
} public string Value
{
get { return _value; }
set { _value = value; }
}
public string Display
{
get { return _display; }
set { _display = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
}
}
MyAttribute
frmMain主窗体
Application.Run(new frmMain()); 为了减少篇幅,就没写这个,但它作为主窗体启动。
mainTree 上的节点是通过反射获取到所有控件和窗体,然后将它们加入到mainTree中
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BackgroundManager.Func; namespace BackgroundManager
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
this.IsMdiContainer = true; InitTreeList();
} private void InitTreeList()
{
GetAssemblyClass getass = new GetAssemblyClass();
Type[] frmTypes = getass.GetFormAssembly();
Type[] ctlTypes = getass.GetUserCtlAssembly();
mainTree.Nodes.Clear(); var typeArray = new List<Type>();
typeArray.AddRange(frmTypes);
typeArray.AddRange(ctlTypes);
foreach (Type type in typeArray)
{
TreeNode node;
string name = type.Name;
MyAttribute[] customAttributes = type.GetCustomAttributes(typeof(MyAttribute), true) as MyAttribute[];
if (customAttributes != null && customAttributes.Length > )
{
name = customAttributes[].Display;
}
node = new TreeNode(name);
node.Tag = type;
mainTree.Nodes.Add(node);
}
} private void mainTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{ } private void mainTree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node != null)
{
Type t = e.Node.Tag as Type;
if (t != null)
{
UserControl c = Activator.CreateInstance(t) as UserControl;
if (c != null)
{
this.splitContainer1.Panel2.Controls.Clear();
this.splitContainer1.Panel2.Controls.Add(c);
c.Dock = DockStyle.Fill;
} Form c2 = Activator.CreateInstance(t) as Form;
if (c2 != null)
{
c2.MdiParent = this;
this.splitContainer1.Panel2.Controls.Clear();
this.splitContainer1.Panel2.Controls.Add(c2);
c2.Dock = DockStyle.Fill;
c2.Show();
}
}
}
} /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmMain));
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.mainTree = new System.Windows.Forms.TreeView();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer1.Location = new System.Drawing.Point(, );
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.AutoScroll = true;
this.splitContainer1.Panel1.Controls.Add(this.mainTree);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.AutoScroll = true;
this.splitContainer1.Size = new System.Drawing.Size(, );
this.splitContainer1.SplitterDistance = ;
this.splitContainer1.TabIndex = ;
//
// mainTree
//
this.mainTree.Dock = System.Windows.Forms.DockStyle.Fill;
this.mainTree.Location = new System.Drawing.Point(, );
this.mainTree.Name = "mainTree";
this.mainTree.Size = new System.Drawing.Size(, );
this.mainTree.TabIndex = ;
this.mainTree.NodeMouseClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.mainTree_NodeMouseClick);
this.mainTree.NodeMouseDoubleClick += new System.Windows.Forms.TreeNodeMouseClickEventHandler(this.mainTree_NodeMouseDoubleClick);
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.splitContainer1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "frmMain";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "后台管理";
this.splitContainer1.Panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false); } #endregion private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.TreeView mainTree; }
}
frmMain
请注意 this.IsMdiContainer = true;
以下四个类为测试控件
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace BackgroundManager.GUI
{
[MyAttribute("","","test1")]
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
} /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(, );
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(, );
this.label1.TabIndex = ;
this.label1.Text = "label1";
//
// UserControl1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label1);
this.Name = "UserControl1";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1;
}
}
UserControl1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace BackgroundManager.GUI
{
public partial class UserControl3 : UserControl
{
public UserControl3()
{
InitializeComponent();
} /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region 组件设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// UserControl3
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.button1);
this.Name = "UserControl3";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1;
}
}
UserControl3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace BackgroundManager.GUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} /// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(, );
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(, );
this.checkBox1.TabIndex = ;
this.checkBox1.Text = "checkBox1";
this.checkBox1.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.ControlBox = false;
this.Controls.Add(this.checkBox1);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout(); } #endregion private System.Windows.Forms.CheckBox checkBox1;
}
}
Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace BackgroundManager.GUI
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} /// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(, );
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(, );
this.button1.TabIndex = ;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.button1);
this.Name = "Form2";
this.Text = "Form2";
this.ResumeLayout(false); } #endregion private System.Windows.Forms.Button button1;
}
}
Form2
生成后运行界面:
这里我们选择的是userControl1,为什么在mainTree中显示的是test1,请仔细看UserControl1中的这段: [MyAttribute("","","test1")],这样可以灵活方便控制控件名称
做一个快乐的程序员
C#中通过反射方法获取控件类型和名称的更多相关文章
- asp:GridView控件使用FindControl方法获取控件的问题
一.使用带cells的指定列 e.Item.Cells[1].Controls[1]只指定第二列的第二个控件 二.不使用带cells的指定类e.Item.FindControl("ID&qu ...
- android自动化测试中hierarchyviewer和uiautomatorviewer获取控件信息的方式比对
http://blog.csdn.net/itfootball/article/details/21777835 http://blog.csdn.net/chenbang110/article/de ...
- Android自动化测试中AccessibilityService获取控件信息(1)
Android自动化测试中AccessibilityService获取控件信息(1) 分类: android自动化测试2014-03-24 15:31 3455人阅读 评论(16) 收藏 举报 and ...
- 怎样在不对控件类型进行硬编码的情况下在 C#vs 中动态添加控件
文章ID: 815780 最近更新: 2004-1-12 这篇文章中的信息适用于: Microsoft Visual C# .NET 2003 标准版 Microsoft Visual C# .NET ...
- Android在OnCreate中获取控件的宽度和高度
在Android中,有时需要对控件进行测量,得到的控件宽度和高度可以用来做一些计算.在需要自适应屏幕的情况下,这种计算就显得特别重要.另一方便,由于需求的原因,希望一进入界面后,就能得到控件的宽度和高 ...
- js中使用控件名和数组下标方式获取控件的值时失败
在做界面展示时涉及到表单行项目的增加和删除时,我们一帮都使用js的脚本实现表单行的增加和删除,那么在进行表单的提交的时我们会再页面上进行提交数据的初步校验,进行数据的初步校验时,就要动态获取控件的值. ...
- WPF线程中获取控件的值和给控件赋值
WPF中使用线程操作控件,按平常的操作方法操作的话会报异常:调用线程无法访问此对象,因为另一个线程拥有该对象.所以我们要使用Dispatcher类的BeginInvoke()与Invoke()方法.B ...
- Android自动化测试中AccessibilityService获取控件信息(2)-三种方式对比
Android自动化测试中AccessibilityService获取控件信息(2)-三种方式对比 上一篇文章: Android自动化测试中AccessibilityService获取控件信息(1 ...
- Silverlight中获取控件中子控件
如题:,直接来看代码: /// <summary> /// 查找并返回第一个 相同 name的子元素 /// </summary> /// <typeparam name ...
随机推荐
- Java对象大小计算
这篇说说如何计算Java对象大小的方法.之前在聊聊高并发(四)Java对象的表示模型和运行时内存表示 这篇中已经说了Java对象的内存表示模型是Oop-Klass模型. 普通对象的结构如下,按64位机 ...
- 简易版C语言程序语法
<程序> -〉 <外部声明> | <函数定义><外部声明> -〉<头文件> | <变量> | <结构体> <头 ...
- 【HDU2896】病毒侵袭 AC自动机
[HDU2896]病毒侵袭 Problem Description 当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻....在这样的时刻,人们却异常兴奋--我们能在有生之年看到500年 ...
- spark scala学习笔记
搞清楚几个概念: 闭包 柯里化 搭建了intellij idea 的scala 开发环境
- hive 创建三种文件类型的表
--TextFile set hive.exec.compress.output=true; set mapred.output.compress=true; set mapred.output.co ...
- bzoj3123: [Sdoi2013]森林
题面传送门 复出的第一道题.. md就遇到坑了.. 简单来说就是可持久化线段树+启发式合并啊.. 感觉启发式合并好神奇好想学 每一次建边就暴力合并,每一个节点维护从根到它的权值线段树 按照题面的话最省 ...
- NOIP2016普及
还记得去年局部变量忘记置零coin爆零的事......结果我今年又要考一年普及[趴 最近沉迷分块莫队无法自拔,这几天才想起来我是个普及组选手 几乎没准备普及,周六上午抱抱佛脚好了...... 希望能顺 ...
- Rust语言的多线程编程
我写这篇短文的时候,正值Rust1.0发布不久,严格来说这是一门兼具C语言的执行效率和Java的开发效率的强大语言,它的所有权机制竟然让你无法写出线程不安全的代码,它是一门可以用来写操作系统的系统级语 ...
- Python3.5 Day1作业:实现用户密码登录,输错三次锁定。
作业需求: 1.输入用户名密码 2.认证成功后显示欢迎信息 3.输错三次后锁定 实现思路: 1.判断用户是否在黑名单,如果在黑名单提示账号锁定. 2.判断用户是否存在,如果不存在提示账号不存在. 3. ...
- Ubuntu 14.04(amd64)安装Oracle11g XE(x64)
下载Oracle安装包 下载地址:Oracle Database Express Edition 11g Release 2 for Linux x64 安装办法 1、建立oracle用户及属主 ad ...