我试图比较object[]单个类型的对象(在运行时未知).它们是System.string,int,decimal,Datetime,或bool类型.
有没有办法比较其中两个对象,以确定一个对象是否大于或小于另一个,而不必先将它们转换为适当的类型?
我试图在winforms中填充一个多色对角线渐变的矩形,如下例所示:对角线渐变 我知道这是一个WPF示例,但是有可能在winforms中得到类似的结果吗?
关于.net中DLL的循环依赖关系的"最佳"实践是什么?
我正在尝试使用DLL来进行需要读/写XML的错误处理/日志记录.
我已经有几个类来帮助在单独的"实用程序"类型DLL中进行XML操作.
将我的fancy-pants错误处理类合并到实用程序DLL中会很好,但我还需要用于错误记录DLL的XML操作代码.
我想我应该保持DLL的分离,以便在其他项目中重复使用,但现在我不确定最好的方法是什么.
有关如何处理这种情况的任何建议?
在显示甚至少量数据时,我一直遇到WPF DataGrid和列表框GridView性能问题.我虽然这个问题只是WPF一般表现不佳,但问题似乎只在于文本块控件.
我创建了一个示例面板,我添加了几个项目.如果我添加简单填充的矩形,调整大小/滚动性能是完美的,但是一旦我使用了文本块,性能就会消失.
看起来性能问题来自于:
child.Measure(constraint);
Run Code Online (Sandbox Code Playgroud)
当测量文本块时,它会使性能停止.有什么我可以覆盖文本块的测量或某些东西来提高性能吗?(我会明确设置孩子的大小)
编辑:我现在已经创建了简化的代码来安排我想要的项目.
此代码的性能很好,除了...当文本块内的文本宽度超过文本块的实际宽度时.这使我的表现回归到爬行 - 可能是因为它试图再次测量元素?
public class TestPanel : Panel
{
private int _rowHeight = 20;
private int _columnWidth = 50;
public TestPanel()
{
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 20; j++)
{
TextBlock cell = new TextBlock();
cell.ClipToBounds = true;
cell.Width = _columnWidth;
cell.Height = _rowHeight;
cell.Text = i.ToString() + ":" + j.ToString();
this.Children.Add(cell);
}
}
}
protected override Size MeasureOverride(Size constraint) …Run Code Online (Sandbox Code Playgroud) 我试图使用try-catch在SQL查询(而不是在存储过程中)中捕获错误.
由于某种原因,这不是处理我的错误,我仍然得到:
消息213,级别16,状态1,行29列名称或提供的值的数量与表定义不匹配.
有什么帮助吗?
begin try
create table #temp_hierarchy
(temp_gl_number varchar(50)
,temp_store_location varchar(255)
,temp_store_key varchar(50)
,temp_serving_dc varchar(50)
,temp_exploris_db varchar(50)
,temp_dc_account varchar(50)
,temp_store_type varchar(50)
,temp_dvp_ops varchar(50)
,temp_rdo varchar(50)
,temp_team varchar(50)
,temp_dvp_sales varchar(50)
,temp_rds varchar(50)
,temp_closed varchar(50)
,temp_open_date varchar(50)
,temp_close_date varchar(50)
,temp_store_manager varchar(250)
,temp_sales_teammate varchar(250)
,temp_machine_shop varchar(50)
,temp_address varchar(250)
,temp_city varchar(50)
,temp_state varchar(50)
,temp_zip varchar(50)
,temp_phone varchar(50)
,temp_fax varchar(50))
insert into #temp_hierarchy
select *
from OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\SQL_DATA_REPORTING\8-31-11 Store Hierarchy.xlsx;HDR=YES',
'SELECT * FROM [Master List$]');
truncate table tbl_hierarchy
insert into tbl_hierarchy
select …Run Code Online (Sandbox Code Playgroud) 我过去曾使用Web发布工具来发布我的MVC 5应用程序,而没有在过去进行预编译。为了减少每个页面的初始加载时间,我修改了发布设置,如下所示,以便在发布过程中预编译应用程序。突然之间,我曾经难以置信的可靠出版变成了一场噩梦。
我对“将所有输出合并到单个程序.cshtml集中”的理解意味着,我所有的页面都将一起编译成Dashboard.Precompiled.dll,然后将其部署到IIS。情况并非如此-当我能够进行发布工作时,它将.complied为.cshtml项目中的每个文件创建一个文件,并且不执行任何合并。
目前的主要问题.compiled是仅在某些时间生成。当我查看obj\Debug\AspnetCompileMerge\TempBuildDir\bin目录时,没有.compiled文件也没有Dashboard.Precompiled.dll。
我尝试过重新启动Visual Studio,清理解决方案并重建,在发布之前预览或不预览更改,创建全新的发布配置文件以及一次又一次地修改高级预编译设置。通常,经过30分钟左右的处理后,我可以使.precompiled文件成功生成和发布,但是我无法确定是什么原因导致该时间段正常工作。下次我不更改任何设置进行发布时,它将再次停止工作。使用VS2015或VS2017RC时会发生此问题。
任何人都可以在这里帮助我指出正确的方向吗?我已经花了很多时间了解这一点,只是感觉到我现在要转圈了。
谢谢!
编辑 我仔细查看了构建输出,发现使用以下参数执行了对aspnet_compiler.exe的调用:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\Users\steve\Source\Dashboard\master\src\Agility.Web\obj\Staging\AspnetCompileMerge\Source -d C:\Users\steve\Source\Dashboard\master\src\Agility.Web\obj\Staging\AspnetCompileMerge\TempBuildDir
当我直接从命令行运行此命令时,不会.compiled生成任何文件TempBuildDir\bin。
O_O
如果我在表中有以下记录:
Parent Child
1 2 <--
2 1 <--
3 2
3 4
Run Code Online (Sandbox Code Playgroud)
等等...
我想识别既是孩子的父母和父母的孩子的记录,例如上面箭头所标识的2条记录,我将如何做到这一点?
我试图在此表上运行一些递归SQL,但这些项目导致无限循环.我想识别这些项目,以便手动解决.
我的大脑因为弄乱递归查询已经足够了,我没有什么可以解决这个问题了.请帮忙 :)
如果我有一个对象,例如List<string>我将其转换为一个对象object,然后再返回,那么所有的字符串是否也会被转换为包含它们的列表?
我认为编译器只需要在重新插入之前检查它是否object是类型List<string>,List<string>但是我在C#中长大,所以我不完全确定我编写的代码背后会发生什么.
我正在将SQL Server 2008迁移到2012,并在为CLR例程创建一些必要的程序集时遇到了挑战.例程依赖于stdole.dll,但我无法创建此程序集.我的代码如下:
ALTER DATABASE main SET TRUSTWORTHY ON;
create assembly [stdole]
from
'C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\stdole.dll'
WITH PERMISSION_SET = unsafe
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Warning: The Microsoft .NET Framework assembly 'stdole, version=7.0.3300.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.' you are registering is not fully tested in the SQL Server hosted environment and is not supported. In the future, if you upgrade or service this assembly or the .NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online for …Run Code Online (Sandbox Code Playgroud) 我有一个查询,我总是想返回 10 条记录:
set rowcount 10
select row_number() over(order by count(*) desc) row_num
,hist_report_id
,max(rpt_report_name) report_name
from utility.dbo.tbl_report_history
join utility.dbo.tbl_report_definitions
on hist_report_id = rpt_report_id
where hist_user_id = 1038
group by hist_report_id
Run Code Online (Sandbox Code Playgroud)
如果我有 10 条或更多记录,这很好用。问题是当记录少于 10 条时,我仍然需要在 report_id 和 report_name 字段中返回带有空值的 rownumber 字段。
如果只返回 7 条记录,结果应如下所示:
row_num report_id report_name
1 id1 name1
2 id2 name2
3 id3 name3
4 id4 name4
5 id5 name5
6 id6 name6
7 id7 name7
8 null null
9 null null
10 null null
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我正在使用 …
我有代码,将大约100,000个项目添加到List.
如果我添加一个字符串或对象数组,代码几乎立即运行(不到100毫秒),但如果我尝试添加一个结构数组,那么.Add调用只需1.5秒.
使用struct []时为什么会有这样的性能影响?
这是我的结构:
public struct LiteRowInfo
{
public long Position;
public int Length;
public int Field;
public int Row;
public LiteRowInfo(long position, int length, int field, int row)
{
this.Position = position;
this.Length = length;
this.Field = field;
this.Row = row;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2:字符串方法的性能比结构的性能要快:我很欣赏这些注释,看起来创建结构本身就有额外的开销.我想我会创建2个单独的列表来存储位置和长度以提高性能.
private void Test()
{
Stopwatch watch = new Stopwatch();
watch.Start();
List<LiteRowInfo[]> structList = new List<LiteRowInfo[]>();
for (int i = 0; i < 100000; i++)
{
LiteRowInfo[] info = new LiteRowInfo[20];
for (int x = …Run Code Online (Sandbox Code Playgroud) c# ×5
sql ×3
sql-server ×3
.net ×2
asp.net ×1
asp.net-mvc ×1
boxing ×1
compareto ×1
dll ×1
generic-list ×1
gradient ×1
object ×1
panel ×1
performance ×1
sqlclr ×1
struct ×1
textblock ×1
try-catch ×1
winforms ×1
wpf ×1