我有一个非常通用的扩展方法来显示控制台中的任何类型的列表:
public static void ShowList<T>(this IEnumerable<T> Values)
{
foreach (T item in Values)
{
Console.WriteLine(item);
}
}
Run Code Online (Sandbox Code Playgroud)
不是我有一个string我可以使用这个方法
string text = "test";
text.ShowList();
Run Code Online (Sandbox Code Playgroud)
但是如果string它在我的应用程序中没有意义.
如何string从这种方法中排除?我读过一些关于
ShowList<T>(this IEnumerable<T> Values): Where != string //doesn't work
Run Code Online (Sandbox Code Playgroud) 我知道XOR的工作,
Console.WriteLine(1^1); // returns 0
Run Code Online (Sandbox Code Playgroud)
结果
00000001
00000001
--------
00000000
Run Code Online (Sandbox Code Playgroud)
但是这又如何回归?
Console.WriteLine(-(-1^1)); // returns 2
Run Code Online (Sandbox Code Playgroud) 我一直在寻找一种方法来限制 TextBox 中的文本,看起来像这样
<asp:TextBox runat="server" ID="tbTest" TextMode="MultiLine"
MaxLength="20" Rows="5" Columns="30" >
</asp:TextBox>
Run Code Online (Sandbox Code Playgroud)
该物业 MaxLength="20"如果其他财产只能TextMode="MultiLine"是未设置。它甚至没有被渲染。
HTML 中的输出如下所示:
<textarea name="ctl00$ContentPlaceHolder1$tbTest"
id="ctl00_ContentPlaceHolder1_tbTest" rows="5" cols="30">
</textarea>
Run Code Online (Sandbox Code Playgroud)
如果您在 SO 上搜索解决此问题的解决方案,您会得到 2 种建议:
asp:RegularExpression) 验证器并验证控件但
大多数答案是 2013 年以前的maxlength,所有浏览器的支持都是从 2013 年 IE10 发布开始的(参考)。
目前每个浏览器都支持这个属性 - 请自行测试:https : //jsfiddle.net/wuu5wne1/
题
如何强制 ASP.Net 将此属性应用于我的多行文本框?
我有一个简单的循环,看起来应该是这样的
for (sbyte i = sbyte.MinValue; i <= sbyte.MaxValue; i++)
{
Console.WriteLine(i);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是sbyte.MaxValue +1 = sbyte.MinValue,这永远不会满足结束条件.我的解决方法是使用intfrom -128,127但是还有原生sbyte方法吗?
我有MVC应用程序返回ResultObjekt后处理FormulaData对象.这是通过HTTP-Post调用的rest API
[HttpPost]
[ActionName("GetResult")]
public ResultObjekt GetResult([FromBody]FormularData values)
{
}
Run Code Online (Sandbox Code Playgroud)
问题:有没有办法从valuesa Dictionary<string, string>或a中读取所有属性IEnumerable<KeyValuePair<string, string>>?
例如
public class FormularData
{
public string Item1 { get; set; }
public string Item2 { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
应该导致a Dictionary<string,string>()或a IEnumerable<KeyValuePair<string, string>>
有价值的 { {"Item1","Value1"}, {"Item2","Value2"}}
我以前的解决方案与之相关Querystring,HttpGet而不是HttpPost因为我改变了,Request.GetQueryNameValuePairs().ToDictionary(x => x.Key, x => x.Value)所以不再适用.
这是我目前的 - 不是那么漂亮的解决方案:
[HttpPost]
[ActionName("GetResult")]
public ResultObjekt GetResult([FromBody]FormularData values)
{
List<KeyValuePair<string, string>> list = …Run Code Online (Sandbox Code Playgroud) 我收到此错误消息:
无法从其"可见"属性的字符串表示形式<%:false%>创建"System.Boolean"类型的对象.
当我尝试在我的ASP.net网站中运行此代码时:
<a runat="server" visible='<%: false %>' href="~/" >Home</a>
Run Code Online (Sandbox Code Playgroud)
有语法错误吗?false应该可以通过任何方法替换:
<asp:Panel runat="server" Visible='<%: GetTrueOrFalse() %>'>Home</a>
Run Code Online (Sandbox Code Playgroud) 我有代码
//this runs
string[] s_items = {"0","0"};
string s_output = string.Format("{0}{1}",s_items);
//this one throws a exception
int[] i_items = {0,0};
string i_output = string.Format("{0}{1}",i_items);
Run Code Online (Sandbox Code Playgroud)
为什么第一个运行而第二个抛出异常?为何选择
int[]在Format(String,?Object)过载
string[]在Format(String,?Object[])过载
我只是注意到该方法有11个重载 string.Concat()
public static string Concat(IEnumerable<string> values);
public static string Concat<T>(IEnumerable<T> values);
public static string Concat(object arg0);
public static string Concat(params object[] args);
public static string Concat(params string[] values);
public static string Concat(object arg0, object arg1);
public static string Concat(string str0, string str1);
public static string Concat(object arg0, object arg1, object arg2);
public static string Concat(string str0, string str1, string str2);
public static string Concat(object arg0, object arg1, object arg2, object arg3);
public static string Concat(string str0, string str1, string …Run Code Online (Sandbox Code Playgroud) 从这里开始,我向自己询问此类查询的 elasticsearch 语法:
WHERE text LIKE "%quick%"
AND text LIKE "%brown%"
AND text LIKE "%fox%"
Run Code Online (Sandbox Code Playgroud)
我的尝试(不幸的是没有成功)
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"terms": {
"text": [
"*quick*",
"*brown*",
"*fox*"
]
}
}
]
}
}
]
}
}
Run Code Online (Sandbox Code Playgroud)