.NET开发中经常用到的扩展方法
整理一下自己经常用到的几个扩展方法,在实际项目中确实好用,节省了不少的工作量。
1 匿名对象转化
在WinForm中,如果涉及较长时间的操作,我们一般会用一个BackgroundWorker来做封装长时间的操作,给它传递一个类型参数。
var parm = new { UserId = txtUserId.Text, UserText = txtText.Text, TabIndex = tabControl.SelectedIndex, CheckUrl = urls,
SupportFormat = supportFormat, DeleteMHT = chkDelete.Checked, FileFormat=supportFileFormat };
backgroundWorker.RunWorkerAsync(parm);
注意到一点,我这里没有用一个类型,而是用一个匿名类型,以节省类型的定义。这种场景经常遇到,比如这个后台方法需要传三个参数,那个后台方法需要五个参数,如果不用我这个方法,那你需要额外的定义二个类型,分别包含三个参数或是五个参数。
再来看DoWork时,如何使用这个匿名方法
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
#region Download
backgroundWorker.ReportProgress(10, string.Format("Analyst beginning......"));
var parm = e.Argument.TolerantCast(new { UserId = string.Empty, UserText = string.Empty, TabIndex = 0,
CheckUrl = new List<string>(), SupportFormat = string.Empty, DeleteMHT = false, FileFormat=string.Empty});
与RunWorkerAsnyc中传递的参数一样,定义一个匿名类型,各属性放默认值,然后调用TolerantCast方法,即可得到前面传入的值。
这个方法很大的方便了这种使用情景:方法与方法之间需要传递不固定的参数,但是又不愿意重新定义一个新的类型。这个方法不来自于CodeProject,我把它的代码转在下面,供您参考
/// <summary>
/// 转换匿名类型
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="o"></param>
/// <param name="example"></param>
/// <returns></returns>
public static T TolerantCast<T>(this object o, T example)
where T : class
{
IComparer<string> comparer = StringComparer.CurrentCultureIgnoreCase;
//Get constructor with lowest number of parameters and its parameters
var constructor = typeof (T).GetConstructors(
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance
).OrderBy(c => c.GetParameters().Length).First();
var parameters = constructor.GetParameters(); //Get properties of input object
var sourceProperties = new List<PropertyInfo>(o.GetType().GetProperties()); if (parameters.Length > 0)
{
var values = new object[parameters.Length];
for (int i = 0; i < values.Length; i++)
{
Type t = parameters[i].ParameterType;
//See if the current parameter is found as a property in the input object
var source = sourceProperties.Find(delegate(PropertyInfo item)
{
return comparer.Compare(item.Name, parameters[i].Name) == 0;
}); //See if the property is found, is readable, and is not indexed
if (source != null && source.CanRead &&
source.GetIndexParameters().Length == 0)
{
//See if the types match.
if (source.PropertyType == t)
{
//Get the value from the property in the input object and save it for use
//in the constructor call.
values[i] = source.GetValue(o, null);
continue;
}
else
{
//See if the property value from the input object can be converted to
//the parameter type
try
{
values[i] = Convert.ChangeType(source.GetValue(o, null), t);
continue;
}
catch
{
//Impossible. Forget it then.
}
}
}
//If something went wrong (i.e. property not found, or property isn't
//converted/copied), get a default value.
values[i] = t.IsValueType ? Activator.CreateInstance(t) : null;
}
//Call the constructor with the collected values and return it.
return (T) constructor.Invoke(values);
}
//Call the constructor without parameters and return the it.
return (T) constructor.Invoke(null);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
2 集合对象上的扩展方法
先看例子,下面的测试方法
var @enum = new[] {1, 2, 3, 4}.AsEnumerable();
var sum = 0;
@enum.ForEach(n => sum += n);
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
这个扩展方法,可以直接在一个集合上执行一个Lambda表达式,返回结果,相当于有二个参数的Fun<T,T>,来看它的源代码定义
public static void ForEach<T>(this IEnumerable<T> @enum, Action<T> mapFunction)
{
foreach (var item in @enum) mapFunction(item);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
3 字符串类型上的扩展方法
这里可以做的扩展方法比较多,一个明显的例子就是,依据String类型写的Helper类型方法最多。
来看一个字符串拼凑的例子,平时我们用string.Format这样的写法,如果用下面的扩展方法,看起来更直观一些。
string s = "{0} ought to be enough for {1}.";
string param0 = "64K";
string param1 = "everybody";
string expected = "64K ought to be enough for everybody.";
Assert.AreEqual(expected, s.FormatWith(param0, param1),
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
这个扩展方法的定义也简单,只有一行代码
/// <summary>
/// Formats a string with two literal placeholders.
/// </summary>
/// <param name="text">The extension text</param>
/// <param name="arg0">Argument 0</param>
/// <param name="arg1">Argument 1</param>
/// <returns>The formatted string</returns>
public static string FormatWith(this string text, object arg0, object arg1)
{
return string.Format(text, arg0, arg1);
}
可以考虑把参数延长到任意个,改写这个扩展方法,也只需要一行代码皆可
/// <summary>
/// Formats a string with two literal placeholders.
/// </summary>
/// <param name="text">The extension text</param>
/// <param name="arg0">Argument 0</param>
/// <param name="arg1">Argument 1</param>
/// <returns>The formatted string</returns>
public static string FormatWith(this string text, params object[] args))
{
return string.Format(text, args);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
另一个有用的扩展方法是字符串与枚举类型之间的转化,扩展方法定义如下
/// <summary>
/// Parses a string into an Enum
/// </summary>
/// <typeparam name="T">The type of the Enum</typeparam>
/// <param name="value">String value to parse</param>
/// <returns>The Enum corresponding to the stringExtensions</returns>
public static T ToEnum<T>(this string value)
{
return ToEnum<T>(value, false);
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
参考下面的例子,使用这个实用的扩展方法
enum ProductVersion
{
Standard,
Enteprise,
Ultimate
} [TestMethod]
public void StringToEnumTest()
{
Assert.AreEqual(ProductVersion.Standard, "Standard".ToEnum<ProductVersion>());
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
4 数字类型上的扩展方法
我这里有一个明显的例子是显示容量的扩展方法,请看下面的方法组:
/// <summary>
/// Kilobytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int KB(this int value)
{
return value * 1024;
} /// <summary>
/// Megabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int MB(this int value)
{
return value.KB() * 1024;
} /// <summary>
/// Gigabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int GB(this int value)
{
return value.MB() * 1024;
} /// <summary>
/// Terabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static long TB(this int value)
{
return (long)value.GB() * (long)1024;
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
用起来就很轻松了,简单的一行代码,获取容量的数字值
var kb = 1.KB();
var mb = 1.MB();
var gb = 1.GB();
var tb = 1.TB();
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
最后一组扩展方法在计算百分比中经常遇到,比如统计计算,任务完成百分比计算:
#region PercentageOf calculations
/// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, int percent)
{
return (decimal)(number * percent / 100);
}
/// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, int total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)position / (decimal)total * 100;
return result;
}
public static decimal PercentOf(this int? position, int total)
{
if (position == null) return 0;
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)((decimal)position / (decimal)total * 100);
return result;
}
/// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, float percent)
{
return (decimal)(number * percent / 100);
}
/// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, float total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)((decimal)position / (decimal)total * 100);
return result;
}
/// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, double percent)
{
return (decimal)(number * percent / 100);
}
/// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, double total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)((decimal)position / (decimal)total * 100);
return result;
}
/// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, decimal percent)
{
return (decimal)(number * percent / 100);
}
/// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, decimal total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)position / (decimal)total * 100;
return result;
}
/// <summary>
/// The numbers percentage
/// </summary>
/// <param name="number">The number.</param>
/// <param name="percent">The percent.</param>
/// <returns>The result</returns>
public static decimal PercentageOf(this int number, long percent)
{
return (decimal)(number * percent / 100);
}
/// <summary>
/// Percentage of the number.
/// </summary>
/// <param name="percent">The percent</param>
/// <param name="number">The Number</param>
/// <returns>The result</returns>
public static decimal PercentOf(this int position, long total)
{
decimal result = 0;
if (position > 0 && total > 0)
result = (decimal)position / (decimal)total * 100;
return result;
}
#endregion
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
来看几个测试用例,增强对它的直观感受,因为涉及到的数值类型多一些,所以扩展方法的数量也多。
Assert.AreEqual(33.0M, 100.PercentageOf(33));
Assert.AreEqual(33.0M, 33.PercentOf(100));
Assert.AreEqual(33.0M, 100.PercentageOf((float)33.0F));
Assert.AreEqual(33.0M, 33.PercentOf((float)100.0F));
Assert.AreEqual(33.0M, 100.PercentageOf((double)33.0F));
Assert.AreEqual(33.0M, 33.PercentOf((double)100.0F));
Assert.AreEqual(33.0M, 100.PercentageOf((decimal)33.0M));
Assert.AreEqual(33.0M, 33.PercentOf((decimal)100.0M));
Assert.AreEqual(33.0M, 100.PercentageOf((long)33));
Assert.AreEqual(33.0M, 33.PercentOf((long)100));
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.NET开发中经常用到的扩展方法的更多相关文章
- java开发中遇到的问题及解决方法(持续更新)
摘自 http://blog.csdn.net/pony12/article/details/38456261 java开发中遇到的问题及解决方法(持续更新) 工作中,以C/C++开发为主,难免与其他 ...
- IOS开发中数据持久化的几种方法--NSUserDefaults
IOS开发中数据持久化的几种方法--NSUserDefaults IOS 开发中,经常会遇到需要把一些数据保存在本地的情况,那么这个时候我们有以下几种可以选择的方案: 一.使用NSUserDefaul ...
- Android应用开发中三种常见的图片压缩方法
Android应用开发中三种常见的图片压缩方法,分别是:质量压缩法.比例压缩法(根据路径获取图片并压缩)和比例压缩法(根据Bitmap图片压缩). 一.质量压缩法 private Bitmap com ...
- 浅谈Excel开发:九 Excel 开发中遇到的常见问题及解决方法
Excel开发过程中有时候会遇到各种奇怪的问题,下面就列出一些本人在开发中遇到的一些比较典型的问题,并给出了解决方法,希望对大家有所帮助. 一 插件调试不了以及错误导致崩溃的问题 在开发机器上,有时可 ...
- 关于html+ashx开发中几个问题的解决方法
在跟html+ashx打交道的园友们肯定会发现,这种模式虽然优美,但在开发中会遇到一些难处理的地方.我也不例外,下面是自己在实际开发中总结出来的几条经验,希望跟大家分享,更希望得到大家的建议和更好的解 ...
- 关于html+ashx开发中几个问题的解决方法 (转)
在跟html+ashx打交道的园友们肯定会发现,这种模式虽然优美,但在开发中会遇到一些难处理的地方.我也不例外,下面是自己在实际开发中总结出来的几条经验,希望跟大家分享,更希望得到大家的建议和更好的解 ...
- droid开发中监听器的三种实现方法(OnClickListener)
Android开发中监听器的实现有三种方法,对于初学者来说,能够很好地理解这三种方法,将能更好地增进自己对android中监听器的理解. 一.什么是监听器. 监听器是一个存在于View类下的接口,一般 ...
- phpcms模块开发中的小问题及解决方法
1.模块菜单中文名出错 在编写安装模块时候可能需要更改extention.inc.php中定义中文名称,由于反复安装或者通过phpcms的扩展->菜单管理 修改菜单名会导致中文名失败.解决办法很 ...
- Hive开发中使用变量的两种方法
在使用hive开发数据分析代码时,经常会遇到需要改变运行参数的情况,比如select语句中对日期字段值的设定,可能不同时间想要看不同日期的数据,这就需要能动态改变日期的值.如果开发量较大.参数多的话, ...
随机推荐
- android开发学习---layout布局、显示单位和如何进行单元测试
一.五大布局(layout) android中的用五大布局:LinearLayout (线性布局).AbsoluteLayout(绝对布局).RelativeLayout(相对布局).TableLay ...
- 面试知识点总结之Java语言
1.如果某个对象出现在字符串表达式中,如System.out.println(this+".class");,则会自动调用this.toString() 2.所有的类都是在对其第一 ...
- 深入理解C语言的函数调用过程
本文主要从进程栈空间的层面复习一下C语言中函数调用的具体过程,以加深对一些基础知识的理解. 先看一个最简单的程序: 点击(此处)折叠或打开 /*test.c*/ #include stdio. ...
- ASP.NET访问网络映射盘&实现文件上传读取功能
最近在改Web的时候,遇到一个问题,要跨机器访问共享文件夹,以实现文件正常上传下载功能. 要实现该功能,可以采用HTTP的方式,也可以使用网络映射磁盘的方式,今天主要给大家分享一下使用网络映射磁盘的方 ...
- 基本套接字编程(4) -- poll篇
1. poll技术 poll函数起源于SVR3,最初局限于流设备.SVR4取消了这种限制,允许poll工作在任何描述符上.poll提供的功能与select类似,不过在处理流设备时,它能够提供额外的信息 ...
- centos 下 Qt Creator 的安装使用
centos 下 Qt Creator 的安装使用 Qt 以其开源,免费,完全面向对象(很容易扩展),允许真正的组件编程以及可移植跨平台等诸多优势得到越来越多的开发人员的青睐.Qt Creator 是 ...
- xtrabackup工具安装
1.首先从官网上http://www.percona.com/下载较新版本的xtrabackup percona-xtrabackup-2.2.7-5050-Linux-x86_64.tar.gz 2 ...
- java中的内部类小结
内部类不是很好理解,但说白了其实也就是一个类中还包含着另外一个类.如同一个人是由大脑.肢体.器官等身体结果组成,而内部类相当于其中的某个器官之一,例如心脏:它也有自己的属性和行为(血液.跳动).显然, ...
- JS判断手机访问跳转到手机站
这里提供了六种让手机端访问网站跳转到手机端的方法: 第一种: <script> if(navigator.platform.indexOf('Win32')!=-1){ //pc //wi ...
- 命令行导入SQL文件
摘要:把数据库导出为XX.sql格式的数据库文件,导入到另外一个数据库中的时候,总是无法全部导入.及时用mysql的命令界面导入依然是无法全部导入.老师告诉我:在命令行中运行的效率和成功率是最快和最高 ...