在C#中,是否保证表达式从左到右进行求值?
例如:
myClass = GetClass();
if (myClass == null || myClass.Property > 0)
continue;
Run Code Online (Sandbox Code Playgroud)
有没有不符合的语言?
c# language-agnostic compiler-construction expression expression-evaluation
我正在将算法从C#转换为C++.该算法的一小部分是计算字典中某些区域的平均值.
字典中的数据按以下方式存储:
Index Value
1 10
3 28
290 78
1110 90
Run Code Online (Sandbox Code Playgroud)
我需要计算索引小于某个数字的所有值的平均值,并且所有索引值都大于某个数字.在C#中我按以下方式执行:
if (dictionary.Where(x => x.Key < areaWidth).Count() > 0)
{
avgValue = (int) dictionary.Where(x => x.Key < areaWidth).Average(
x => x.Value);
}
for (var i = 0; i < line.Length; i++)
{
if (i == areaWidth)
{
avgValue = -1;
i = line.Length - areaWidth;
var rightBorder = i - areaWidth;
if (dictionary.Where(x => x.Key > (rightBorder)).Count() > 0)
{
avgValue = (int) dictionary.Where(
x => x.Key > …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一种旋转图像的方法,以便在此图像中剪切一个矩形并将其另存为单独的图片.
编辑:请参阅已接受的解决方案.
我必须在Windows窗体应用程序中显示一个大图像.用户应该可以标记图像的区域,然后应该像下面所示的示例一样进行缩放.
如前所述,图像会非常大,所以我的问题是:是否可以使用默认PictureBox
控件实现此功能,或者我最好使用第三方控件?如果是这样,请推荐一个包含提供这些功能的控件的库.
正如所承诺的,这是我制作的控件的来源:
/// <summary>
/// A panel used to display an image and zoom into areas of the displayed
/// image.
/// </summary>
public sealed class PictureZoomPanel : Panel
{
// The image to dispay, set in the Image property
private Image _image;
// The current zoom factor
private float _zoom = 1;
// The zoom rectangle on the panel.
private Rectangle _panelZoomRect;
// _panelZoomRect on the actual image
private Rectangle? _imageZoomRect;
// Used in the mouse …
Run Code Online (Sandbox Code Playgroud) 我最近在我们的一台服务器上安装了一个PHP下载门户.一切正常,但用户无法上传大文件(~20 MB).
我将以下设置设置为极大值或无限制:
memory_limit
upload_max_filesize
post_max_size
memory_limit
Run Code Online (Sandbox Code Playgroud)
全php.ini
在这里:http://pastebin.com/NrqJvMVM
但重启服务器后仍然失败.
我错过了一个设置吗?我是否必须更新Apache配置中的任何值?公司防火墙可能会以某种方式干扰吗?
编辑:我检查了phpinfo(),主配置仍显示旧值.但是,配置文件C:\ Windows\php.ini具有新值.我使用了错误的配置文件.
是否可以将OleDbCommand
所有参数的文本替换为其值?例如,在下面的代码中,我正在寻找一种获取查询文本的方法
SELECT * FROM my_table WHERE c1 = 'hello' and c2 = 'world'
Run Code Online (Sandbox Code Playgroud)
在我完成分配参数后.
var query = "SELECT * FROM my_table WHERE c1 = ? and c2 = ?";
var cmd = new OleDbCommand(query, connection);
cmd.Parameters.Add("@p1", OleDbType.WChar).Value = "hello";
cmd.Parameters.Add("@p2", OleDbType.WChar).Value = "world";
Run Code Online (Sandbox Code Playgroud) 我目前正在重构代码以将Convert.To替换为TryParse.
我遇到了以下一些代码,它们创建并为对象分配属性.
List<Person> list = new List<Person>();
foreach (DataRow row in dt.Rows)
{
var p = new Person{ RecordID = Convert.ToInt32(row["ContactID"]) };
list.Add(p);
}
Run Code Online (Sandbox Code Playgroud)
我作为替代品提出的是:
var p = new Person { RecordID = Int32.TryParse(row["ContactID"].ToString(), out RecordID) ? RecordID : RecordID };
Run Code Online (Sandbox Code Playgroud)
有什么想法,意见,替代我做过的事情?
作为Linux中的新手,我有以下问题.我有文件列表(这次是由svn状态产生的),我想创建一个脚本来循环它们并用4个空格替换制表符.
所以我想要
....
D HTML/templates/t_bla.tpl
M HTML/templates/t_list_markt.tpl
M HTML/templates/t_vip.tpl
M HTML/templates/upsell.tpl
M HTML/templates/t_warranty.tpl
M HTML/templates/top.tpl
A + HTML/templates/t_r1.tpl
....
Run Code Online (Sandbox Code Playgroud)
喜欢的东西
for i in <files>; expand -t4;do cp $i /tmp/x;expand -t4 /tmp/x > $i;done;
Run Code Online (Sandbox Code Playgroud)
但我不知道该怎么做......
我有一个包含很多NCHAR(n)
列的数据库.其中一些列是简单属性,但有些也是主键或外键.
有许多表和列以及大量的测试数据.
将每NCHAR(n)
列转换NVARCHAR(n)
为相同长度的列并修剪其内容的最佳方法是什么?
如果你能想到比更改设计器中的列更好的事情,记住列名并在脚本窗口中修剪它,请将其作为答案发布.
我使用smarty和mysql_real_escape_string()
用户输入,当我用'
或插入一些代码"
,并在phpmyadmin中查找它显示没有反斜杠.
当我从DB获得记录时,我也没有反斜杠.但是,当我只是传递转义字符串而不插入数据库时,它会被反击.
不应该添加斜线,插入它们然后我会在输出时剥离它们?或者我错过了什么?
c# ×3
php ×2
.net ×1
ado.net ×1
apache ×1
average ×1
c++ ×1
escaping ×1
exception ×1
expression ×1
file-upload ×1
large-files ×1
linux ×1
loops ×1
map ×1
mysql ×1
oledb ×1
parameters ×1
picturebox ×1
refactoring ×1
rotation ×1
shell ×1
smarty ×1
sql-server ×1
stl ×1
svn ×1
tryparse ×1
winforms ×1
wpf ×1
zooming ×1