将DataTable转换为PagedCollectionView数据,我们可以借用DataTable的GetBindableData()方法,如下:

 DataTable dt=new DataTable();
PagedCollectionView m_pagedCollectionView = new PagedCollectionView(dt.GetBindableData(new Connector()));
this.daDatas.ItemsSource = m_pagedCollectionView;

问题:如果直接调用GetBindableData方法的话,我们得到的所有PagedCollectionView数据将都是string类型的,为了得到数据类型的数据,我们可以自己写转换方法

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
using SuperMap.Web.ISDotNET6;
using WaterWebGIS.MainFrame.BL;
using SL40PropertyGrid;
using System.ComponentModel;
using Silverlight;
using WaterWebGIS.QueryStatServiceProxy;
using DataColumn = Silverlight.DataColumn;
using DataRow = Silverlight.DataRow;
using DataTable = Silverlight.DataTable;
using FieldInfo = WaterWebGIS.QueryStatServiceProxy.FieldInfo; namespace WaterWebGIS.Business.DataModel
{
public class TypeFactory
{
private static List<CategoryPriorityInfo> s_categoryPriorityInfo;
private static Dictionary<string, Type> s_dicTypes;
private static AssemblyBuilder s_asmBuilder;
private static ModuleBuilder s_modBuilder; /// <summary>
/// 获取分类优先级信息
/// </summary>
public static void GetCategoryPriorityInfo()
{
QueryStatServiceSoapClient client = (QueryStatServiceSoapClient)WaterWebGIS.Business.Utility.CreateWebServiceObject(typeof(QueryStatServiceSoapClient), "/WS/QueryService/QueryStatService.asmx");
client.GetCategoryPriorityAsync();
client.GetCategoryPriorityCompleted += new EventHandler<GetCategoryPriorityCompletedEventArgs>(client_GetCategoryPriorityCompleted);
} static void client_GetCategoryPriorityCompleted(object sender, GetCategoryPriorityCompletedEventArgs e)
{
if (e.Error == null)
{
s_categoryPriorityInfo = new List<CategoryPriorityInfo>();
foreach (CategoryPriorityInfo info in e.Result)
{
s_categoryPriorityInfo.Add(info);
}
}
} /// <summary>
/// 将数据库中的基础数据类型转换为.Net框架中的数据类型
/// </summary>
/// <param name="dbType">将数据库中保存的类型信息转换成.net中相应的类型</param>
public static Type ToDotNetTypeFromDBType(string dbType)
{
if (dbType.ToLower() == "varchar" || dbType.ToLower() == "datetime")
{
return typeof(System.String);
}
else if (dbType.ToLower() == "int")
{
return typeof(System.Int32);
}
else if (dbType.ToLower() == "float")
{
return typeof(System.Double);
} return typeof(DBNull);
} /// <summary>
/// 生成应用程序集和模块
/// </summary>
private static void GenerateAssemboyAndModule()
{
if (s_asmBuilder == null)
{
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "DynamicORMapper";
AppDomain thisDomain = Thread.GetDomain();
s_asmBuilder = thisDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
s_modBuilder = s_asmBuilder.DefineDynamicModule(assemblyName.Name);
}
} /// <summary>
/// 创建类型
/// </summary>
/// <param name="modBuilder">模块生成器</param>
/// <param name="layer">图层信息</param>
/// <returns>类型信息</returns>
private static Type CreateType(ModuleBuilder modBuilder, WaterWebGIS.QueryStatServiceProxy.GISLayer layer)
{
TypeBuilder typeBuilder = modBuilder.DefineType(layer.LayerNameEN, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); CreateConstructor(typeBuilder);
CreateProperties(typeBuilder, layer.FieldENlist); return typeBuilder.CreateType();
} /// <summary>
/// 创建类型
/// </summary>
/// <param name="modBuilder">模块生成器</param>
/// <param name="table">DataTable信息</param>
/// <returns>类型信息</returns>
private static Type CreateType(ModuleBuilder modBuilder, DataTable table)
{
string tableName = "Table" + Environment.TickCount;
TypeBuilder typeBuilder = modBuilder.DefineType(tableName, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); CreateConstructor(typeBuilder);
CreateProperties(typeBuilder, table.Columns); return typeBuilder.CreateType();
} /// <summary>
/// 创建类构造函数
/// </summary>
/// <param name="typeBuilder">类型生成器</param>
private static void CreateConstructor(TypeBuilder typeBuilder)
{
ConstructorBuilder construtor = typeBuilder.DefineConstructor(MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, new Type[]);
ConstructorInfo conObj = typeof(object).GetConstructor(new Type[]); ILGenerator il = construtor.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, conObj);
il.Emit(OpCodes.Ret);
} /// <summary>
/// 创建类属性信息
/// </summary>
/// <param name="typeBuilder">类型生成器</param>
/// <param name="fieldInfoCollection">图层字段集合</param>
private static void CreateProperties(TypeBuilder typeBuilder, ObservableCollection<WaterWebGIS.QueryStatServiceProxy.FieldInfo> fieldInfoCollection)
{
foreach (WaterWebGIS.QueryStatServiceProxy.FieldInfo fi in fieldInfoCollection)
{
if (fi.IsVisible == true)
{
FieldBuilder fieldBuilder = typeBuilder.DefineField("m" + fi.FieldENName, ToDotNetTypeFromDBType(fi.FieldType), FieldAttributes.Private); PropertyBuilder propertyBuilder = typeBuilder.DefineProperty(fi.FieldENName, PropertyAttributes.HasDefault, ToDotNetTypeFromDBType(fi.FieldType), null); Type[] ctorParams = new Type[] { typeof(string) };
ConstructorInfo classCtorInfo = typeof(DisplayNameAttribute).GetConstructor(ctorParams);
CustomAttributeBuilder customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { fi.FieldAlias });
propertyBuilder.SetCustomAttribute(customAttributeBuilder); classCtorInfo = typeof(CategoryAttribute).GetConstructor(ctorParams);
customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { fi.Category });
propertyBuilder.SetCustomAttribute(customAttributeBuilder); ctorParams = new Type[] { typeof(int) };
classCtorInfo = typeof(CategoryPriorityAttribute).GetConstructor(ctorParams);
customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { GetCategoryPriorityValueByCategoryName(fi.Category) });
propertyBuilder.SetCustomAttribute(customAttributeBuilder); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
MethodBuilder getMethodBuilder = typeBuilder.DefineMethod("get_" + fi.FieldENName, getSetAttr, ToDotNetTypeFromDBType(fi.FieldType), Type.EmptyTypes);
ILGenerator ilGenerator = getMethodBuilder.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret); MethodBuilder setMethodBuilder = typeBuilder.DefineMethod("set_" + fi.FieldENName, getSetAttr, null, new Type[] { ToDotNetTypeFromDBType(fi.FieldType) });
ilGenerator = setMethodBuilder.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldarg_1);
ilGenerator.Emit(OpCodes.Stfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret); propertyBuilder.SetGetMethod(getMethodBuilder);
propertyBuilder.SetSetMethod(setMethodBuilder);
}
}
} /// <summary>
/// 根据分类名称获取该分类的显示优先级
/// </summary>
/// <param name="categoryName">分类名称</param>
/// <returns>显示优先级</returns>
private static int GetCategoryPriorityValueByCategoryName(string categoryName)
{
if (s_categoryPriorityInfo != null)
{
foreach (CategoryPriorityInfo info in s_categoryPriorityInfo)
{
if (info.CategoryName == categoryName)
{
return info.Priority;
}
}
} return int.MaxValue;
} /// <summary>
/// 创建类属性信息
/// </summary>
/// <param name="typeBuilder">类型生成器</param>
/// <param name="dataColumnCollection">DataColumnCollection</param>
private static void CreateProperties(TypeBuilder typeBuilder, DataColumnCollection dataColumnCollection)
{
foreach (DataColumn dataColumn in dataColumnCollection)
{
FieldBuilder fieldBuilder = null;
if (dataColumn.DataType == typeof(DateTime))
{
fieldBuilder = typeBuilder.DefineField("m_" + dataColumn.ColumnName, typeof(string), FieldAttributes.Private);
}
else
{
fieldBuilder = typeBuilder.DefineField("m_" + dataColumn.ColumnName, typeof(string), FieldAttributes.Private);
} PropertyBuilder propertyBuilder = null;
if (dataColumn.DataType == typeof(DateTime))
{
propertyBuilder = typeBuilder.DefineProperty(dataColumn.ColumnName, PropertyAttributes.HasDefault, typeof(string), null);
}
else
{
propertyBuilder = typeBuilder.DefineProperty(dataColumn.ColumnName, PropertyAttributes.HasDefault, typeof(string), null);
} Type[] ctorParams = new Type[] { typeof(string) };
ConstructorInfo classCtorInfo = typeof(DisplayNameAttribute).GetConstructor(ctorParams); MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig;
MethodBuilder getMethodBuilder = typeBuilder.DefineMethod("get_" + dataColumn.ColumnName, getSetAttr, typeof(string), Type.EmptyTypes);
ILGenerator ilGenerator = getMethodBuilder.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret); MethodBuilder setMethodBuilder = typeBuilder.DefineMethod("set_" + dataColumn.ColumnName, getSetAttr, null, new Type[] { typeof(string) });
ilGenerator = setMethodBuilder.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldarg_1);
ilGenerator.Emit(OpCodes.Stfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret); propertyBuilder.SetGetMethod(getMethodBuilder);
propertyBuilder.SetSetMethod(setMethodBuilder);
}
} /// <summary>
/// 根据类名获取相应的类信息
/// </summary>
/// <param name="typeName">类名</param>
/// <returns>类</returns>
public static Type GetTypeByTypeName(string typeName)
{
try
{
if (s_dicTypes == null)
{
if (s_asmBuilder == null)
{
GenerateAssemboyAndModule();
} s_dicTypes = new Dictionary<string, Type>(); foreach (WaterWebGIS.QueryStatServiceProxy.GISLayer gisLayer in BasicGISService.GetLayers().LayerList)
{
try
{
Type type = CreateType(s_modBuilder, gisLayer);
s_dicTypes.Add(gisLayer.LayerNameEN, type);
}
catch
{
} }
} if (s_dicTypes.ContainsKey(typeName))
{
return s_dicTypes[typeName];
}
else
{
return null;
}
}
catch
{
return null;
}
} public static object CreateObjectBaseOnLayerInfoAndObjectValue(WaterWebGIS.QueryStatServiceProxy.GISLayer gisLayer, SelectAction objectValue)
{
try
{
Type type = GetTypeByTypeName(gisLayer.LayerNameEN);
if (type != null)
{
object obj = Activator.CreateInstance(type);
if (obj != null)
{
foreach (WaterWebGIS.QueryStatServiceProxy.FieldInfo fi in gisLayer.FieldENlist)
{
string fieldValue = BasicGISService.GetLayers().GetValueFromRecord(objectValue.RecordSet, objectValue.Record, fi.FieldENName);
object value = ConvertStringValueToSpecifyTypeValue(fieldValue, fi.FieldType); if (fi.FieldType == "datetime")
{
if (((DateTime)value) == DateTime.MinValue)
{
value = string.Empty;
}
else
{
value = value.ToString();
}
}
if (fi.FieldType == "float")
{
value = Math.Round(Convert.ToDouble(value), );
} PropertyInfo propertyInfo = type.GetProperty(fi.FieldENName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
if (propertyInfo != null)
{
propertyInfo.SetValue(obj, value, null);
}
}
} return obj;
} return null;
}
catch
{
return null;
}
} /// <summary>
/// 将字符串值转换成指定类型的值
/// </summary>
/// <returns>转换后的对象值</returns>
private static object ConvertStringValueToSpecifyTypeValue(string value, string dbType)
{
if (dbType.ToLower() == "varchar")
{
return value;
}
else if (dbType.ToLower() == "int")
{
int temp = ;
int.TryParse(value, out temp);
return temp;
}
else if (dbType.ToLower() == "float")
{
float temp = ;
float.TryParse(value, out temp);
return temp;
}
else if (dbType.ToLower() == "datetime")
{
DateTime datetime;
if (DateTime.TryParse(value, out datetime))
{
if (value != "0:00:00")
{
return datetime;
}
else
{
DateTime superMapDate = new DateTime(, , , , , );
return superMapDate;
}
}
else
{
return new DateTime();
}
} return null;
} public static Type CreateTypeBaseOnDataTable(DataTable table)
{
if (s_asmBuilder == null)
{
GenerateAssemboyAndModule();
} return CreateType(s_modBuilder, table);
} /// <summary>
/// 根据DataTable返回相应的对象集合
/// </summary>
/// <param name="table">DataTable</param>
/// <returns>对象集合</returns>
public static List<object> CreateObjectCollectionBaseOnDataTable(DataTable table)
{
if (table == null)
{
throw new ArgumentNullException("table不能为空!");
} List<object> collection = new List<object>(); try
{
Type type = CreateTypeBaseOnDataTable(table); if (type != null)
{
foreach (DataRow row in table.Rows)
{
object obj = Activator.CreateInstance(type);
if (obj != null)
{
foreach (DataColumn column in table.Columns)
{
PropertyInfo propertyInfo = type.GetProperty(column.ColumnName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
if (propertyInfo != null)
{
if (!string.IsNullOrEmpty(row[column.ColumnName]))
{
propertyInfo.SetValue(obj, ConvertStringToSpecifyType(column.DataType.FullName, row[column.ColumnName]), null);
}
}
}
} collection.Add(obj);
}
} return collection;
}
catch
{
return collection;
}
} private static object ConvertStringToSpecifyType(string typeName, string value)
{
switch (typeName)
{
case "System.Int32":
//return int.Parse(value);
return value;
case "System.DateTime":
DateTime? temp = DateTime.Parse(value);
return temp.Value.ToString();
case "System.Double":
//return double.Parse(value);
return value;
case "System.Decimal":
//return Decimal.Parse(value);
return value;
case "System.Byte":
//return byte.Parse(value);
return value;
case "System.String":
default:
return value;
}
} #region 除指定列转换为string类型,其他类型按所给的数据类型进行转换
//add by qzl @hn at20140424
/// <summary>
/// 除指定列转换为string类型,其他类型按所给的数据类型进行转换
/// </summary>
/// <param name="gisLayer">图层</param>
/// <param name="objectValue">数据集</param>
/// <param name="lstFiledName">转换为string类型的列</param>
/// <returns></returns>
public static object CreateObjectBaseOnLayerInfoAndObjectValueAndChangeText(GISLayer gisLayer, SelectAction objectValue, List<string> lstFiledName)
{
try
{
Type type = GetTypeByTypeNameToString(gisLayer.LayerNameEN, lstFiledName);
if (type != null)
{
object obj = Activator.CreateInstance(type);
if (obj != null)
{
foreach (FieldInfo fi in gisLayer.FieldENlist)
{
object value;
if (lstFiledName.Contains(fi.FieldENName.ToLower()))
{
value ="******";
}
else
{
string fieldValue = BasicGISService.GetLayers().GetValueFromRecord(objectValue.RecordSet, objectValue.Record, fi.FieldENName);
value = ConvertStringValueToSpecifyTypeValue(fieldValue, fi.FieldType);
if (fi.FieldType == "datetime")
{
value = ((DateTime)value) == DateTime.MinValue ? string.Empty : value.ToString();
}
if (fi.FieldType == "float")
{
value = Math.Round(Convert.ToDouble(value), );
}
}
PropertyInfo propertyInfo = type.GetProperty(fi.FieldENName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.SetProperty);
if (propertyInfo != null)
{
propertyInfo.SetValue(obj, value, null);
}
}
} return obj;
} return null;
}
catch
{
return null;
}
} /// <summary>
/// 根据类名获取相应的类信息
/// </summary>
/// <param name="typeName">类名</param>
/// <returns>类</returns>
public static Type GetTypeByTypeNameToString(string typeName, List<string> lstFiledName)
{
try
{
if (s_dicTypes == null)
{
if (s_asmBuilder == null)
{
GenerateAssemboyAndModule();
}
s_dicTypes = new Dictionary<string, Type>(); foreach (GISLayer gisLayer in BasicGISService.GetLayers().LayerList)
{
try
{
Type type = CreateTypeToString(s_modBuilder, gisLayer, lstFiledName);
s_dicTypes.Add(gisLayer.LayerNameEN, type);
}
catch
{
}
}
} if (s_dicTypes.ContainsKey(typeName))
{
return s_dicTypes[typeName];
}
return null;
}
catch
{
return null;
}
}
/// <summary>
/// 创建类型
/// </summary>
/// <param name="modBuilder">模块生成器</param>
/// <param name="layer">图层信息</param>
/// <returns>类型信息</returns>
private static Type CreateTypeToString(ModuleBuilder modBuilder, GISLayer layer, List<string> lstFiledName)
{
TypeBuilder typeBuilder = modBuilder.DefineType(layer.LayerNameEN, TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.AutoClass | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit | TypeAttributes.AutoLayout); CreateConstructor(typeBuilder);
CreatePropertiesToString(typeBuilder, layer.FieldENlist, lstFiledName); return typeBuilder.CreateType();
} /// <summary>
/// 创建类属性信息
/// </summary>
/// <param name="typeBuilder">类型生成器</param>
/// <param name="fieldInfoCollection">图层字段集合</param>
private static void CreatePropertiesToString(TypeBuilder typeBuilder,
IEnumerable<FieldInfo> fieldInfoCollection, List<string> lstFiledName)
{
foreach (FieldInfo fi in fieldInfoCollection)
{
if (fi.IsVisible == true)
{
MethodBuilder setMethodBuilder;
MethodBuilder getMethodBuilder;
FieldBuilder fieldBuilder;
PropertyBuilder propertyBuilder;
MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.SpecialName |
MethodAttributes.HideBySig;
if (lstFiledName.Contains(fi.FieldENName.ToLower()))
{
fieldBuilder = typeBuilder.DefineField("m" + fi.FieldENName,
typeof(string),
FieldAttributes.Private);
propertyBuilder = typeBuilder.DefineProperty(fi.FieldENName,
PropertyAttributes.HasDefault,
typeof(string),
null);
getMethodBuilder = typeBuilder.DefineMethod("get_" + fi.FieldENName, getSetAttr,
typeof(string),
Type.EmptyTypes);
setMethodBuilder = typeBuilder.DefineMethod("set_" + fi.FieldENName, getSetAttr,
null,
new Type[]
{
typeof(string)
});
}
else
{
fieldBuilder = typeBuilder.DefineField("m" + fi.FieldENName,
ToDotNetTypeFromDBType(fi.FieldType),
FieldAttributes.Private);
propertyBuilder = typeBuilder.DefineProperty(fi.FieldENName,
PropertyAttributes.HasDefault,
ToDotNetTypeFromDBType(fi.FieldType),
null);
getMethodBuilder = typeBuilder.DefineMethod("get_" + fi.FieldENName, getSetAttr,
ToDotNetTypeFromDBType(fi.FieldType),
Type.EmptyTypes);
setMethodBuilder = typeBuilder.DefineMethod("set_" + fi.FieldENName, getSetAttr,
null,
new Type[]
{
ToDotNetTypeFromDBType(
fi.FieldType)
});
} Type[] ctorParams = new Type[] { typeof(string) };
ConstructorInfo classCtorInfo = typeof(DisplayNameAttribute).GetConstructor(ctorParams);
CustomAttributeBuilder customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo,
new object[] { fi.FieldAlias });
propertyBuilder.SetCustomAttribute(customAttributeBuilder); classCtorInfo = typeof(CategoryAttribute).GetConstructor(ctorParams);
customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo, new object[] { fi.Category });
propertyBuilder.SetCustomAttribute(customAttributeBuilder); ctorParams = new Type[] { typeof(int) };
classCtorInfo = typeof(CategoryPriorityAttribute).GetConstructor(ctorParams);
customAttributeBuilder = new CustomAttributeBuilder(classCtorInfo,
new object[]
{
GetCategoryPriorityValueByCategoryName
(fi.Category)
});
propertyBuilder.SetCustomAttribute(customAttributeBuilder); ILGenerator ilGenerator = getMethodBuilder.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret);
ilGenerator = setMethodBuilder.GetILGenerator();
ilGenerator.Emit(OpCodes.Ldarg_0);
ilGenerator.Emit(OpCodes.Ldarg_1);
ilGenerator.Emit(OpCodes.Stfld, fieldBuilder);
ilGenerator.Emit(OpCodes.Ret); propertyBuilder.SetGetMethod(getMethodBuilder);
propertyBuilder.SetSetMethod(setMethodBuilder);
}
}
} //end
#endregion
}
}

Silverlight中如何自己写方法将DataTable转换为PagedCollectionView数据(动态创建类)的更多相关文章

  1. C#中使用Buffer.BlockCopy()方法将string转换为byte array的方法:

    public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count); 将指定数目的字 ...

  2. 【转载】 C#中使用float.Parse方法将字符串转换为Float类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为单精度Float类型就是一个常见的类型转换操作,float.Parse方法是C#中专门用来将字符串转换为float类型的,f ...

  3. 【转载】C#中使用float.TryParse方法将字符串转换为Float类型

    在C#编程过程中,将字符串string转换为单精度float类型过程中,时常使用float.Parse方法,但float.Parse在无法转换的时候,会抛出程序异常,其实还有个float.TryPar ...

  4. 【转载】C#中使用double.TryParse方法将字符串转换为double类型

    在C#编程过程中,将字符串string转换为double类型过程中,时常使用double.Parse方法,但double.Parse在无法转换的时候,会抛出程序异常,其实还有个double.TryPa ...

  5. 【转载】C#中使用double.Parse方法将字符串转换为双精度double类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为双精度浮点类型double就是一个常见的类型转换操作,double.Parse方法是C#中专门用来将字符串转换为double ...

  6. 【转载】 C#中使用decimal.Parse方法将字符串转换为十进制decimal类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为十进制decimal类型就是一个常见的类型转换操作,decimal.Parse方法是C#中专门用来将字符串转换为decima ...

  7. 【转载】C#中使用decimal.TryParse方法将字符串转换为十进制decimal类型

    在C#编程过程中,将字符串string转换为decimal类型过程中,时常使用decimal.Parse方法,但decimal.Parse在无法转换的时候,会抛出程序异常,其实还有个decimal.T ...

  8. 【转载】 C#中使用int.TryParse方法将字符串转换为整型Int类型

    在C#编程过程中,将字符串string转换为整型int过程中,时常使用的转换方法为int.Parse方法,但int.Parse在无法转换的时候,会抛出程序异常,其实还有个int.TryParse方法可 ...

  9. 【转载】C#中使用int.Parse方法将字符串转换为整型Int类型

    在C#编程过程中,很多时候涉及到数据类型的转换,例如将字符串类型的变量转换为Int类型就是一个常见的类型转换操作,int.Parse方法是C#中专门用来将字符串转换为整型int的,int.Parse方 ...

随机推荐

  1. 关于string转整数

    又是leetcode的easy级别题,很基本的题目,却漏考虑很多情况,动手前一定要考虑清楚呀!!! 就当做锻炼写作能力吧,先上题目! 将文本转换成整数,注意一下几点: 1.文本里面第一个不为空白的字符 ...

  2. 在GNU/Linux下使用命令行自动挂载与卸载USB磁盘

    在命令行环境下如果每次都是靠手动敲入mount与umount命令来挂载与卸载USB磁盘是件很麻烦的事情.尤其是mount命令的参数非常多.比如,磁盘的分区类型(vfat.ntfs等),挂载的目录节点, ...

  3. Scala分号推断

    看这样段代码,Scala会把它当作两个语句,x 和 +y,如果想把它作为一个语句,可以把它们放在括号里(x+y) x +y 或者也可以把 + 放在行末,也正因为此,串接类似于 + 这样的中缀操作符的时 ...

  4. 怎样成为PHP 方向的一个合格的架构师(转)

    突然看到这篇文章, 值得反省, 乐在其中, 在接下来的发展中不被淘汰的都来看看, 如何成为一个架构师先明确这里所指的PHP工程师,是指主要以PHP进行Web系统的开发,没有使用其的语言工作过.工作经验 ...

  5. Knockout js 绑定 radio 时,当绑定整形的时候,绑定不生效

    解决方案: 使用checkedValue和checked 组合,如下代码. <div><input type="radio" name="flavorG ...

  6. Linux安装mysql mysql5.5.40 <NIOT>

    一.    操作系统与软件 操作系统及版本 Centos 6.4 依赖包 gcc.gcc-c++.cmake.ncurses-devel 下载目录 /opt Mysql安装目录 /usr/local/ ...

  7. Win内存分配函数(GlobalAlloc/HeapAlloc/LocalAlloc/VirtualAlloc)

    Win内存分配函数(GlobalAlloc/HeapAlloc/LocalAlloc/VirtualAlloc) 来源:http://blog.csdn.net/chunyexiyu/article/ ...

  8. sql server 自定义split 标值函数

    自定义一个函数,分隔一个以分隔符的隔开字符串,例如把'1,3,5,7,9' 变成 数字1 3 5 7 9的结果集. 自定义标值函数: ),)) )) --实现split功能 的函数 as begin ...

  9. chrome手动添加拓展

    https://www.crx4chrome.com/crx/978/ Free Download Postman REST Client CRX 0.8.4.19 for ------------- ...

  10. [妙味Ajax]第三课:AJAX跨域解决方案:JSONP

    知识点总结: JSONP(JSON with Padding): 1.script标签 2.用script标签加载资源是没有跨域问题的 在资源加载进来之前定义好一个函数,这个函数接收一个参数(数据), ...