C#知识点三则

2014-08-07  籽藤 

字符数组和字符串的相互转换

byte[] byteArray = System.Text.Encoding.Default.GetBytes( str ); string str = System.Text.Encoding.Default.GetString( byteArray );

将Dictionary内容写入txt文件

File.WriteAllLines("myfile.txt", dictionary.Select(x => "[" + x.Key + " " + x.Value + "]").ToArray());

在匿名方法的内部不能访问不安全的代码。也不能访问在匿名方法外部定义的ref和out参数

private static bool ExportTablesForTenantSubInfo(List<long> tenantIds, string grouping_uniqueid, string folderName, out Dictionary<long,string> failedTables) { //Just use a copy. it isn't allowed to use out or ref parameters inside lambda expressions. var tempTables = new Dictionary<long,string>(); var tenantsWithPartition = SqlHelper.GetPartitions(tenantIds, Environment.customer); foreach (var t in tenantsWithPartition) { int partition = 0; if (t.Value.HasValue) { partition = (int)t.Value; } List<string> tables = DBTables.Load4SpecTables("tables.xml", "TenantSubInfo"); tables.AsParallel().ForAll(table =>{ var whereClause = string.Format("WHERE i_billable_acct_id IN ({0})", t.Key.ToString()); var query = buildExportQuery(table, whereClause); ("ExportTables4Tenant: " + table + partition.ToString() + query + grouping_uniqueid + folderName).WriteLine(LogSeverity.Verbose); if (!exportData(Databases.Subscription, table, partition, query, grouping_uniqueid, folderName)) { //Output the failed tables with tenant Id tempTables.Add(t.Key,table); } }); } failedTables = tempTables; return failedTables.Count> 0 ? false : true ; }
359°/3594 人阅读/0 条评论 发表评论

登录 后发表评论