在SQL Server中,您可以使用该IsNull()
函数检查值是否为null,如果是,则返回另一个值.现在我想知道C#中是否有类似的东西.
例如,我想做类似的事情:
myNewValue = IsNull(myValue, new MyValue());
Run Code Online (Sandbox Code Playgroud)
代替:
if (myValue == null)
myValue = new MyValue();
myNewValue = myValue;
Run Code Online (Sandbox Code Playgroud)
谢谢.
这是一种方法 -
using System;
class Program
{
static void Main(string[] args)
{
//
// Create an array of four bytes.
// ... Then convert it into an integer and unsigned integer.
//
byte[] array = new byte[4];
array[0] = 1; // Lowest
array[1] = 64;
array[2] = 0;
array[3] = 0; // Sign bit
//
// Use BitConverter to convert the bytes to an int and a uint.
// ... The int and uint can have different values if the …
Run Code Online (Sandbox Code Playgroud) 我正在维护一个公司内部Visual Studio扩展,它被打包并部署为VSIX容器.此扩展目前针对VS 2010.它使用几个VS API DLL并引用它们的VS 2010版本.
我目前正在迁移此扩展程序以与VS 2012/2013兼容.我已经发现可以手动编辑旧的VSIX清单以允许扩展另外安装到VS 2012/2013 - 这非常有效.
但是我目前使用的一些VS 2010 API与VS 2012 ++不兼容,我需要更新它们 - 具有放弃向后兼容性的效果.
我的问题是:我应该如何构建我的解决方案和VSIX以便它与VS 2010,2012和2013兼容.是否可以使用一个针对VS 2010的DLL和一个针对VS 2012/2013的DLL并选择一个使用的在延长加载时间?
旁注:我正在使用MEF来构建我的内部功能单元.这会让它变得更容易吗?
我正在研究基于WCF的客户端/服务器应用程序(WCF是自托管的,而不是在IIS中).
WCF服务具有将一大块数据上载到服务器的操作.合约大致如下:
void UploadChunk(int clientId, byte[] chunk);
Run Code Online (Sandbox Code Playgroud)
我们正在使用Windows身份验证(Kerberos/NTLM),因此我们无法在此处使用流式传输.
绑定看起来像这样(客户端和服务器端):
new BasicHttpBinding
{
Security = new BasicHttpSecurity
{
Mode = BasicHttpSecurityMode.TransportCredentialOnly,
Transport = { ClientCredentialType = HttpClientCredentialType.Windows },
},
MaxReceivedMessageSize = 0x7fffffff,
ReaderQuotas = { MaxArrayLength = 0x800000 },
};
Run Code Online (Sandbox Code Playgroud)
客户端通过派生自的代理对象与服务进行通信System.ServiceModel.ClientBase<TChannel>
.
所有这一切都很好,但我们观察到WCF客户端每次发送两次HTTP请求,一次没有auth头,再一次使用正确的auth头.这是有问题的,因为请求将非常大,并且此行为导致请求大小是实际块大小的两倍.
我已经发现(https://weblog.west-wind.com/posts/2010/Feb/18/NET-WebRequestPreAuthenticate-not-quite-what-it-sounds-like)设置 WebRequest.PreAuthenticate
为true
记住auth标头并重新使用它适用于后续请求.
但是从我看到的到现在为止,WCF没有公开修改WebRequest实例的机制.
这个问题有什么解决方案吗?
我目前正在更改公司内部的VS扩展以支持Visual Studio 2012.我正在努力的是如何使UI动态地适应活动的VS主题.
我找到了几个颜色/画笔的资源键(Microsoft.VisualStudio.Shell.11.0.dll中的VsColors/VsBrushes),我可以轻松地使用它来更改扩展的基本颜色方案.问题是标准控件(文本框,组合框,复选框)具有默认的WPF外观,看起来很奇怪.
所以问题是:是否有可能在VS扩展的WPF工具窗口中制作标准控件看起来与Visual Studio中使用的类似?我知道我可以自己使用控件模板或自定义控件来做到这一点,但我真的想在某种程度上避免这种努力.
出于好奇,我想测试将GenericList与ArrayList进行比较的刻度数.
对于下面的代码,当我检查秒表时,ArrayList似乎更快.
我做错了还是有解释?(我相信List会更快)
测试代码和输出如下:
private static void ArrayListVsGenericList()
{
// Measure for ArrayList
Stopwatch w0 = new Stopwatch();
w0.Start();
ArrayList aList = new ArrayList();
for (int i = 0; i < 1001; i++)
{
Point p = new Point();
p.X = p.Y = i;
aList.Add(p);
}
foreach (Point point in aList)
{
int v0 = ((Point) aList[8]).X; //unboxing
}
w0.Stop();
// Measure for Generic List<Point>
Stopwatch w1 = new Stopwatch();
w1.Start();
List<Point> list = new List<Point>();
for (int i …
Run Code Online (Sandbox Code Playgroud) 我不能让这个工作.我有一个MemoryStream对象.此类有一个Position属性,可以告诉您已读取的字节数.
我想要做的是删除0和位置1之间的所有字节
我试过这个:
MemoryStream ms = ...
ms.SetLength(ms.Length - ms.Position);
Run Code Online (Sandbox Code Playgroud)
但在某些时候我的数据被破坏了.
所以我最终做到了这一点
MemoryStream ms = ...
byte[] rest = new byte[ms.Length - ms.Position];
ms.Read(rest, 0, (int)(ms.Length - ms.Position));
ms.Dispose();
ms = new MemoryStream();
ms.Write(rest, 0, rest.Length);
Run Code Online (Sandbox Code Playgroud)
哪个有效,但效率不高.
任何想法我怎么能让这个工作?
谢谢
我想实现MVP模式.我有一个用户控件有一些文本框,当我把它放在表单中时,我从usercontrol调用一个方法并填充文本框.但在mvp模式中,我不知道如何访问usercontrol1.fill()
.你有一个可以帮助我的例子吗?
我正在添加一个这样的callout视图:
func mapView(mapView: MKMapView!,
didSelectAnnotationView view: MKAnnotationView!) {
let calloutView = UIView(frame:
CGRect(x: 0, y: 0, width: 300, height: 120))
calloutView.backgroundColor = UIColor.purpleColor()
calloutView.center = CGPointMake(CGRectGetWidth(view.bounds) / 2.0, 0.0)
calloutView.layer.anchorPoint = CGPointMake(0.5, 1.0)
calloutView.layer.masksToBounds = false
calloutView.userInteractionEnabled = true
let calloutViewTapRecognizer = UITapGestureRecognizer(target: self,
action: "onCalloutViewTap")
calloutView.addGestureRecognizer(calloutViewTapRecognizer)
view.addSubview(calloutView)
}
Run Code Online (Sandbox Code Playgroud)
虽然我的onCalloutViewTap
函数从未被调用过......但我很想知道为什么以及能够处理与我的标注视图交互的东西.