为什么在这种情况ReferenceEquals下对象的方法表现不同?
string a= "fg";
string b= "fg";
Console.WriteLine(object.ReferenceEquals(a, b));
Run Code Online (Sandbox Code Playgroud)
所以在这种情况下,它会得到一个结果true.如果是,它会比较我的字符串的值而不是引用.但是当我写下这样的话:
StringBuilder c = new StringBuilder("fg");
string d = c.ToString();
Console.WriteLine(object.ReferenceEquals(a, d));
Run Code Online (Sandbox Code Playgroud)
在这种情况下,它工作正常,结果是false,因为它比较我的对象的引用.
在创建WCF服务的过程中,我遇到了一个对我来说不熟悉的术语.基本上在指定时InstanceContextMode我有几个选项,包括; PerSession,PerCall和Single.这是我正在学习的示例中的代码:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
public class EvalService : IEvalService { ...
Run Code Online (Sandbox Code Playgroud)
现在,他说这样做只会在运行时创建一个服务实例.这是什么意思?我认为,每次与Web服务建立连接时,它都被视为一个单独的实例.
对于每个请求,它是否仍然存在,这是我的服务实例?根据文档中提到的其他成员来判断,假设这是它的工作方式是否安全?
这让我坚持不懈!
我ComboBox习惯过滤员工的查询工作正常,但只显示员工的名字.我想使用a MultiValueConverter来显示员工的全名(如果我们没有2个Mikes和2个Daves,那就不那么紧急了)
下面是我的工作代码和IMultiValueConverter类(为了简洁,修剪了不必要的格式).我已经尝试了一切我能想到的让MultiConverter工作但我没有运气.
<ComboBox ItemsSource="{Binding Path=EmployeesFilter}"
DisplayMemberPath="EmpFirstName"
SelectedValue="{Binding Path=EmployeeToShow, Mode=TwoWay}"/>
Run Code Online (Sandbox Code Playgroud)
它绑定的ViewModel属性:
// This collection is used to populate the Employee Filter ComboBox
private ObservableCollection<Employee> employeesFilter;
public ObservableCollection<Employee> EmployeesFilter
{
get {
return employeesFilter;
}
set {
if (employeesFilter != value)
{
employeesFilter = value;
OnPropertyChanged("EmployeesFilter");
}
}
}
// This property is TwoWay bound to the EmployeeFilters SelectedValue
private Employee employeeToShow;
public Employee EmployeeToShow
{
get {
return employeeToShow;
}
set {
if (employeeToShow …Run Code Online (Sandbox Code Playgroud) 我对VBA没有多少经验,但我有时会在工作中使用它.最近,我遇到了一个不应该发生的问题,我的老板和我自己都不知道.
基本上,问题是该Application属性默认DisplayAlerts设置为True无法由于某种原因而无法更改.可能相关的是,当我遇到错误时,它总是显示End | Debug | Help警告,并且永远不会遇到应用的错误处理.
我在64位Windows 7计算机上运行64位Office 2010.但是,我不认为这是一个平台问题,因为我已经在多个不同平台,操作系统和软件排列上进行了测试,没有其他机器出现此错误; 就是我的.
我已经创建了一些示例代码,以防任何人以前遇到过此问题或有任何想法.我唯一能想到的是,我的机器上安装了一些导致这种情况的东西.但是在程序清除和重启之后,我并没有更接近破译它可能是什么.
Public Sub TestErrorHandler()
' Suppress alerts
Application.DisplayAlerts = False
Dim strArray(1) As String
strArray(0) = "Hello"
strArray(1) = "World"
' Set up error handler
On Error GoTo ErrHandler
For i = 0 To 3
MsgBox strArray(i)
Next
' Strip the error handler
On Error GoTo 0
' Unsuppress alerts
Application.DisplayAlerts = True
Exit Sub
ErrHandler:
MsgBox "Error: " & Err.Description
Resume Next
End …Run Code Online (Sandbox Code Playgroud) 我正在使用Silverlight项目中的XmlReader编写文件阅读器.但是,我遇到了一些错误(特别是围绕XmlReader.ReadStartElement方法),这让我误以为我误解了如何在途中使用它.
基本上,这是我正在使用的Xml格式的示例:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<root>
<EmptyElement />
<NonEmptyElement Name="NonEmptyElement">
<SubElement Name="SubElement" />
</NonEmptyElement>
</root>
Run Code Online (Sandbox Code Playgroud)
以下是一些代码的示例,其使用方式与我使用它的方式相同:
public void ReadData(XmlReader reader)
{
// Move to root element
reader.ReadStartElement("root");
// Move to the empty element
reader.ReadStartElement("EmptyElement");
// Read any children
while(reader.ReadToNextSibling("SubEmptyElement"))
{
// ...
}
// Read the end of the empty element
reader.ReadEndElement();
// Move to the non empty element
reader.ReadStartElement("NonEmptyElement"); // NOTE: This is where I get the error.
// ...
}
Run Code Online (Sandbox Code Playgroud)
所以,基本上,我只是想读取每个元素和任何包含的子元素.我在突出显示的点上得到的错误如下:
错误说明
[Xml_InvalidNodeType]参数:无,10,8调试资源字符串不可用.通常,密钥和参数提供了足够的信息来诊断问题.请参阅http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.51204.0&File=System.Xml.dll&Key=Xml_InvalidNodeType
错误堆栈跟踪
在----------------的System.Xml.XmlReader.ReadStartElement(String name) …
是否可以在属性上分配属性并使用它来分配其他属性 - 这样做而不使用反射?
代码:
public class CashierOut : BaseActivity
{
[Description("Flag indicates whether break to execution.")]
[DefaultValue(false)]
[MyCustomAttribute(ParameterGroups.Extended)]
public bool CancelExecution { get; set; }
[Description("Flag indicates whether allow exit before declation.")]
[DefaultValue(true)]
[MyCustomAttribute(ParameterGroups.Extended)]
[DisplayName("Exit before declaration?")]
public bool AllowExitBeforeDeclare { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想做这样的事情:
public class CashierOut : BaseActivity
{
[MyResourceCustom("CashierOut.CancelExecution")]
public bool CancelExecution { get; set; }
[MyResourceCustom("CashierOut.AllowExitBeforeDeclare")]
public bool AllowExitBeforeDeclare { get; set; }
}
public sealed class MyResourceCustom : Attribute
{
public string ResourcePath { …Run Code Online (Sandbox Code Playgroud) 我在C#中创建动态线程,我需要获取那些运行线程的状态.
List<string>[] list;
list = dbConnect.Select();
for (int i = 0; i < list[0].Count; i++)
{
Thread th = new Thread(() =>{
sendMessage(list[0]['1']);
//calling callback function
});
th.Name = "SID"+i;
th.Start();
}
for (int i = 0; i < list[0].Count; i++)
{
// here how can i get list of running thread here.
}
Run Code Online (Sandbox Code Playgroud)
如何获得正在运行的线程列表?
我试图第一次使用MVVM模式.所以我ItemsControl填充了我的viewmodel对象,使用DataTemplate's 显示; 对象是"节点"和"边缘",DataTemplate用Thumb和Polyline对象表示,我希望能够检测到点击和拖动ItemsControl,以便移动节点和边缘.
两个问题:
Polyline's和Thumb?(我可以将一个Thumb.DragDelta处理程序附加到ItemsControl并e.OriginalSource指向Thumb,但是如何获取相应的viewmodel对象?)ItemsControl到检测鼠标单击和拖动空白区域?(答案如下)注意:我知道如果它直接处理View的事件,它可能不被认为是正确的ViewModel.但重要的是,我需要处理鼠标事件,我不知道如何附加它们.
我在本机DLL中有以下函数头:
unsigned char* Version_String()
Run Code Online (Sandbox Code Playgroud)
我试图从C#项目调用它,我尝试了以下调用(在此处的其他类似问题中找到):
[DllImport("BSL430.dll", CharSet=CharSet.Ansi)]
public extern static UIntPtr Version_String();
Run Code Online (Sandbox Code Playgroud)
我一直得到以下异常:
尝试读取或写入受保护的内存.这通常表明其他内存已损坏.
下一个尝试是以下,我得到相同的例外:
[DllImport("BSL430.dll", CharSet=CharSet.Ansi)]
[return : MarshalAs(UnmanagedType.LPStr)]
public extern static string Version_String();
Run Code Online (Sandbox Code Playgroud)
我似乎无法解决这个问题.任何帮助将不胜感激!
编辑:
我不能在这里给出DLL代码,因为它属于NDA,但我调用的函数看起来像这样:
unsigned char versionString[50];
__declspec(dllexport) unsigned char* Version_String()
{
if(check_hardware_stuff())
{
strcpy((char *) versionString, "version_string_bla_bla");
versionString[5] = stuff;
}
else if (other_check())
{
//will return empty string, that should be filled with '\0'
}
else
{
strcpy( (char *) versionString, "ERROR" );
}
return versionString;
}
Run Code Online (Sandbox Code Playgroud)
我并不特别喜欢DLL实现,但我需要"按原样"使用它.无论我VersionString()对返回值做什么,每次尝试调用时都会抛出异常.
检查集合是否有物品的最佳做法是什么?
这是我的一个例子:
var terminalsToSync = TerminalAction.GetAllTerminals();
if(terminalsToSync.Any())
SyncTerminals(terminalsToSync);
else
GatewayLogAction.WriteLogInfo(Messages.NoTerminalsForSync);
Run Code Online (Sandbox Code Playgroud)
该GetAllTerminals()方法将执行一个存储过程,如果我们返回一个结果(Any()is true),SyncTerminals()将循环遍历这些元素; 从而再次枚举它并第二次执行存储过程.
避免这种情况的最佳方法是什么?
我想要一个可以在其他情况下使用的好解决方案; 可能没有把它转换成List.
提前致谢.
c# ×8
.net ×2
wpf ×2
attributes ×1
data-binding ×1
datatemplate ×1
equals ×1
events ×1
excel ×1
linq ×1
marshalling ×1
mvvm ×1
pinvoke ×1
return ×1
silverlight ×1
string ×1
threadpool ×1
vba ×1
wcf ×1
xaml ×1
xmlexception ×1
xmlreader ×1