我有几个方法都具有相同的签名(参数和返回值),但不同的名称和方法的内部是不同的.我想传递方法的名称以运行到另一个将调用传入方法的方法.
public int Method1(string)
{
... do something
return myInt;
}
public int Method2(string)
{
... do something different
return myInt;
}
public bool RunTheMethod([Method Name passed in here] myMethodName)
{
... do stuff
int i = myMethodName("My String");
... do more stuff
return true;
}
public bool Test()
{
return RunTheMethod(Method1);
}
Run Code Online (Sandbox Code Playgroud)
此代码不起作用,但这是我想要做的.我不明白的是如何编写RunTheMethod代码,因为我需要定义参数.
有没有办法通过.NET/C#找出CPU内核的数量?
PS这是一个直接的代码问题,而不是"我应该使用多线程吗?" 题!:-)
我正在使用基本身份验证来保护仅在公司网络内部公开的一组WCF Web服务,我想知道当Web服务返回401时,是否有办法触发浏览器的凭据对话框从AJAX调用中显示错误?
目前,我的AJAX调用将401作为常规失败请求接收,并且不会提示浏览器执行任何操作.但是,如果我使用相同的URI并将其复制粘贴到浏览器的URL栏中,则返回的401会正确触发"基本身份验证"对话框.
有没有办法让AJAX回调告诉浏览器弹出该对话框?
这篇文章的标题很难想到,所以如果你能想到更具描述性的标题,请告诉我.无论如何,我的问题非常具体,需要一些简单的数学知识.我正在编写一个C#WinForms应用程序,它有点像旧的'xeyes'Linux应用程序.它基本上是一组跟随鼠标光标的眼睛.这听起来可能很容易,但是如果你像我这样的完美主义者会变得相当复杂:P.到目前为止这是我的代码(只有paint方法,间隔为16).
int lx = 35;
int ly = 50;
int rx;
int ry;
int wx = Location.X + Width / 2;
int wy = Location.Y + Height / 2;
Rectangle bounds = Screen.FromControl(this).Bounds;
// Calculate X
float tempX = (mx - wx) / (float)(bounds.Width / 2);
// Calculate Y
float tempY = (my - wy) / (float)(bounds.Height / 2);
// Draw eyes
e.Graphics.FillEllipse(Brushes.LightGray, 10, 10, 70, 100);
e.Graphics.FillEllipse(Brushes.LightGray, 90, 10, 70, 100);
// Draw pupils (this only draws the left …Run Code Online (Sandbox Code Playgroud) 我试图找出当前JavaScript在运行脚本标签的位置.什么是怎么回事的是,我需要确定里面一个src'd,动态插入的JavaScript文件所在的DOM.这些是动态生成的标签; 代码段:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>where am i?</title>
<script type="text/javascript" charset="utf-8">
function byId(id) {
return document.getElementById(id);
}
function create_script(el, code) {
var script = document.createElement("script");
script.type = "text/javascript";
script.text = code;
el.appendChild(script);
}
</script>
</head>
<body>
<div id="find_me_please"></div>
<script>
create_script(byId("find_me_please"), "alert('where is this code located?');");
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 在Sublime Text 3(build 3126)中,是否可以禁用平滑滚动效果?我宁愿让它像Visual Studio那样滚动,它没有为滚动设置动画.这是我的意思的GIF录音:
如果没有正常设置,我愿意使用插件.
我有以下代码,它在表格中显示四个图像。CSS的原因float: left;是让它们换行。JSFiddle
<table>
<tr>
<td style="float: left; padding: 20px;">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=600%C3%97300&w=600&h=300" />
<div style="padding-top: 30px;">TEST TEXT #1</div>
</td>
<td style="float: left; padding: 20px;">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=600%C3%97300&w=600&h=300" />
<div style="padding-top: 30px;">TEST TEXT #2</div>
</td>
<td style="float: left; padding: 20px;">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=600%C3%97300&w=600&h=300" />
<div style="padding-top: 30px;">TEST TEXT #3</div>
</td>
<td style="float: left; padding: 20px;">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=600%C3%97300&w=600&h=300" />
<div style="padding-top: 30px;">TEST TEXT #4</div>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
然而,它们目前固定在表格行的左侧(这是可以理解的,因此是float: leftCSS)。但是,有没有一种方法可以在使 <td> 元素在 <tr> 元素内部居中对齐的同时获得浮动的环绕效果?
是的,我确实必须使用桌子。
c# ×3
.net ×2
javascript ×2
ajax ×1
alignment ×1
cpu-cores ×1
css ×1
delegates ×1
graphics ×1
html ×1
html-table ×1
math ×1
methods ×1
sublimetext3 ×1
wcf ×1
wcf-security ×1
winforms ×1