在具有单个字符串属性的简单引用类型的大序列中搜索Diana有一个有趣的结果.
using System;
using System.Collections.Generic;
using System.Linq;
public class Customer{
public string Name {get;set;}
}
Stopwatch watch = new Stopwatch();
const string diana = "Diana";
while (Console.ReadKey().Key != ConsoleKey.Escape)
{
//Armour with 1000k++ customers. Wow, should be a product with a great success! :)
var customers = (from i in Enumerable.Range(0, 1000000)
select new Customer
{
Name = Guid.NewGuid().ToString()
}).ToList();
customers.Insert(999000, new Customer { Name = diana }); // Putting Diana at the end :)
//1. System.Linq.Enumerable.DefaultOrFirst() …Run Code Online (Sandbox Code Playgroud) 有没有更好的方法来做到这一点......
MyString.Trim().Replace("&", "and").Replace(",", "").Replace(" ", " ")
.Replace(" ", "-").Replace("'", "").Replace("/", "").ToLower();
Run Code Online (Sandbox Code Playgroud)
我已经扩展了字符串类以使其保持一个工作但是有更快的方法吗?
public static class StringExtension
{
public static string clean(this string s)
{
return s.Replace("&", "and").Replace(",", "").Replace(" ", " ")
.Replace(" ", "-").Replace("'", "").Replace(".", "")
.Replace("eacute;", "é").ToLower();
}
}
Run Code Online (Sandbox Code Playgroud)
只是为了好玩(以及停止评论中的论点),我已经推动了以下各种示例的基准测试.
正则表达式选项得分非常高; 字典选项最快; stringbuilder replace的long winded版本比short hand稍快.
我在视图上有一组链接到两个列表的下拉控件.
//control
ViewData["Countries"] = new SelectList(x.getCountries().ToList(), "key","value",country);
ViewData["Regions"] = new SelectList(x.getRegions(country).ToList(), "id", "name", regions);
/*
on the view
*/
<% using (Html.BeginForm("","", FormMethod.Get))
{ %>
<ol>
<li>
<%= MvcEasyA.Helpers.LabelHelper.Label("Country", "Country:")%>
<%= Html.DropDownList("Country", ViewData["Countries"] as SelectList) %>
<input type="submit" value="countryGO" class="ddabtns" />
</li>
<li>
<%= MvcEasyA.Helpers.LabelHelper.Label("Regions", "Regions:")%>
<%= Html.DropDownList("Regions", ViewData["Regions"] as SelectList,"-- Select One --") %>
<input type="submit" value="regionsGO" class="ddabtns" />
</li>
</ol>
<br />
<input type="submit" value="go" />
<% } %>
Run Code Online (Sandbox Code Playgroud)
因此它将查询发送到同一页面(因为它只提供了另一种设置/更新相应下拉菜单的方法,这是可以接受的,因为它将全部用javascript替换).
点击的网址就像......
http://localhost:1689/?country=FRA®ions=117
Run Code Online (Sandbox Code Playgroud)
区域取决于国家/地区代码.
我正在努力实现这一点,而不必担心路由,因为关于这个功能没有真正的意义.
因此Controller具有以下方法.
public ActionResult Index(string …Run Code Online (Sandbox Code Playgroud) 这种方法看起来很愚蠢而且有点沉重; 有没有更好的方法来创建相同的东西(它的MVC视图下拉列表)
private List<KeyValuePair<int, string>> getMonthListDD
{
get
{
var dDur = new List<KeyValuePair<int, string>>();
dDur.Add(new KeyValuePair<int, string>(1, "January"));
dDur.Add(new KeyValuePair<int, string>(2, "Febuary"));
dDur.Add(new KeyValuePair<int, string>(3, "March"));
dDur.Add(new KeyValuePair<int, string>(4, "April"));
dDur.Add(new KeyValuePair<int, string>(5, "May"));
dDur.Add(new KeyValuePair<int, string>(6, "June"));
dDur.Add(new KeyValuePair<int, string>(7, "July"));
dDur.Add(new KeyValuePair<int, string>(8, "August"));
dDur.Add(new KeyValuePair<int, string>(9, "September"));
dDur.Add(new KeyValuePair<int, string>(10, "October"));
dDur.Add(new KeyValuePair<int, string>(11, "November"));
dDur.Add(new KeyValuePair<int, string>(12, "December"));
return dDur;
}
}
Run Code Online (Sandbox Code Playgroud) 我有这个功能......
private string dateConvert(string datDate)
{
System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo("en-GB");
System.Globalization.CultureInfo cultEnUs = new System.Globalization.CultureInfo("en-US");
DateTime dtGb = Convert.ToDateTime(datDate, cultEnGb.DateTimeFormat);
datDate = dtGb.ToString(cultEnUs.DateTimeFormat.ShortDatePattern);
return datDate;
}
Run Code Online (Sandbox Code Playgroud)
但是我想要它仍然在低位数(1-9)的前导零,所以日期是11-09-2009(mm-dd-yyyy)...
现在如果我没有转换它id使用string.Format("{0:d}",dateVar)我如何在转换中执行此操作?
*****解决方案*****
使用下面答案的略微修改版本(即将呈现的一个).
Convert.ToDateTime(datDate).ToString("MM-dd-yyyy");
Run Code Online (Sandbox Code Playgroud) 我一直致力于我的项目深度学习语言检测,这是一个具有这些层的网络,可以从16种编程语言中识别:
这是生成网络的代码:
# Setting up the model
graph_in = Input(shape=(sequence_length, number_of_quantised_characters))
convs = []
for i in range(0, len(filter_sizes)):
conv = Conv1D(filters=num_filters,
kernel_size=filter_sizes[i],
padding='valid',
activation='relu',
strides=1)(graph_in)
pool = MaxPooling1D(pool_size=pooling_sizes[i])(conv)
flatten = Flatten()(pool)
convs.append(flatten)
if len(filter_sizes)>1:
out = Concatenate()(convs)
else:
out = convs[0]
graph = Model(inputs=graph_in, outputs=out)
# main sequential model
model = Sequential()
model.add(Dropout(dropout_prob[0], input_shape=(sequence_length, number_of_quantised_characters)))
model.add(graph)
model.add(Dense(hidden_dims))
model.add(Dropout(dropout_prob[1]))
model.add(Dense(number_of_classes))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud)
所以我的最后一个语言类是SQL,在测试阶段,它永远无法正确预测SQL,它的得分为0%.我认为这是由于SQL样本质量差(实际上它们很差)所以我删除了这个类并开始训练15个类.令我惊讶的是,现在F#文件的检测率为0%,而F#是删除SQL后的最后一个类(即最后一个位置为1且其余为0的单热矢量).现在,如果一个训练有16的网络用于对抗15,那么它将获得98.5%的非常高的成功率.
我使用的代码非常简单,主要在defs.py和data_helper.py中提供
以下是针对16个类测试的16个课程的网络训练结果:
Final result: 14827/16016 (0.925761738262)
xml: 995/1001 (0.994005994006)
fsharp: …Run Code Online (Sandbox Code Playgroud) 我以前使用过如何在ASP.NET MVC中枚举formcollection?的实施,但现在我在VS2010和MVC2抱怨:
Error 1 Cannot implicitly convert type 'System.Web.Mvc.IValueProvider' to 'System.Collections.Generic.IDictionary'. An explicit conversion exists (are you missing a cast?) C:\~\ProjectMVC\Controllers\TheController.cs line ProjectMVC
代码是......
IDictionary<string, ValueProviderResult> tmpCollection = collection.ToValueProvider();
for (int j = 1; j <= noprops; j++)
{
string shopNmTmp =
(from t in tmpCollection
where t.Key.StartsWith(j + ".discount.sname." + j)
select t.Value.AttemptedValue).First();
string shopCdTmp =
(from t in tmpCollection
where t.Key.StartsWith(j + ".discount.sref." + j)
select t.Value.AttemptedValue).First();
...
Run Code Online (Sandbox Code Playgroud)
当我不看时,有什么改变; 这编译,工作和运行,在MVC1中没有问题; 但不会在2中编译.
谢谢
我通过使用以下技术来解决这个问题:
Dictionary<string, string> …Run Code Online (Sandbox Code Playgroud) 我正在使用下面的代码来拉取我们的第三方开发页面中的一个,因此我可以将其解析为XML以用于我的随机工作.
我们有兴趣在服务器上设置浏览器检测级别,只允许某些浏览器访问该站点; 所以问题是如何伪造它以便服务器认为它是浏览器请求?
static string GetHtmlPage(string strURL)
{
String strResult;
System.Net.WebResponse objResponse;
System.Net.WebRequest objRequest = System.Net.HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (System.IO.StreamReader sr = new System.IO.StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}
Run Code Online (Sandbox Code Playgroud) 将CouchDB文档数据库(相同结构)导出到CSV的最简单方法是什么?
我猜它会涉及编写一个视图并使用PHP,C#或Python等手动解析每个文档.
但是有一种更简单的方法或已经存在的东西我可以使用吗?
是否有与SharpSVN和普通SVN/VisSVN开发相关的良好资源和站点?
到目前为止,我只发现了一些与JIRA有关的样本.
c# ×6
c#-3.0 ×3
asp.net ×2
asp.net-mvc ×2
.net ×1
c#-2.0 ×1
couchdb ×1
csv ×1
datetime ×1
export ×1
http-headers ×1
immutability ×1
keras ×1
keras-2 ×1
linq ×1
performance ×1
python ×1
refactoring ×1
sharpsvn ×1
string ×1