举个例子:
interface IEntity {
string Name { get; set; }
}
class Product : IEntity {
public string Name { get; set; }
public int Count { get; set; } // added member
}
class Client {
void Process() {
var product = new Product();
int count = product.Count; // this is valid
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,什么是产品类型?是IEntity还是产品?看来产品是具体实施类型(产品).如果是这种情况,则不应仅在特殊情况下使用var.但我发现像resharper这样的工具建议默认使用var.不应该有一个程序到界面?
Ninject是否具有统一注册实例的等效方法.
我想创建一个模拟对象并注册它.
谢谢
我有一个带有安全类的WCF服务,用于获取调用用户的一些属性.然而,当涉及到线程安全时,我非常糟糕 - 到目前为止,我并不需要对它做太多的事情,而只是对多线程问题有一个基本的理论上的理解.
鉴于以下功能:
public class SecurityService
{
public static Guid GetCurrentUserID()
{
if (Thread.CurrentPrincipal is MyCustomPrincipal)
{
MyCustomIdentity identity = null;
MyCustomPrincipal principal = (MyCustomPrincipal)Thread.CurrentPrincipal;
if (principal != null)
{
identity = (MyCustomIdentity)principal.Identity;
}
if (identity != null)
{
return identity.UUID;
}
}
return Guid.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
如果从2个不同的线程同时调用该方法,是否有可能出现问题?在我的噩梦中,如果这些方法出错,我会看到可怕的后果,例如有人意外地获取其他人的数据或突然变成系统管理员.一位同事(他也不是专家,但他比我好)认为它可能没问题,因为那里没有真正的共享资源.
或者这个将访问数据库的人 - 这可能会出错吗?
public static User GetCurrentUser()
{
var uuid = GetCurrentUserID();
if (uuid != null)
{
var rUser = new UserRepository();
return rUser.GetByID(uuid);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
关于线程的原理有很多讨论,但是当涉及到实际应用它时,我倾向于陷入困境并且知道何时应用它.任何帮助赞赏.
如果不清楚,我可以更详细地解释这些功能的背景/目的.
编辑: …
我想以编程方式为我的Internet Explorer启用/禁用代理 - C#可以帮助我这方面吗?
提前谢谢,Ravi Naik.
编辑:我添加了示例的源代码.
我遇到了这个例子:
char source[MAX] = "123456789";
char source1[MAX] = "123456789";
char destination[MAX] = "abcdefg";
char destination1[MAX] = "abcdefg";
char *return_string;
int index = 5;
/* This is how strcpy works */
printf("destination is originally = '%s'\n", destination);
return_string = strcpy(destination, source);
printf("after strcpy, dest becomes '%s'\n\n", destination);
/* This is how strncpy works */
printf( "destination1 is originally = '%s'\n", destination1 );
return_string = strncpy( destination1, source1, index );
printf( "After strncpy, destination1 becomes '%s'\n", destination1 );
Run Code Online (Sandbox Code Playgroud)
哪个产生了这个输出: …
我使用以下代码打开一个新窗口:
purchaseWin = window.open("Purchase.aspx","purchaseWin2", "location=0,status=0,scrollbars=0,width=700,height=400");
Run Code Online (Sandbox Code Playgroud)
我想访问purchaseWin的dom树,例如
purchaseWin.document.getElementById("tdProduct").innerHTML = "2";
Run Code Online (Sandbox Code Playgroud)
它不起作用.我只能这样做:
purchaseWin.document.write("abc");
Run Code Online (Sandbox Code Playgroud)
我也试过这个,它也不起作用:
$(purchaseWin.document).ready(function(){
purchaseWin.$("#tdProduct").html("2");
});
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我正在尝试编写一个while循环,通过使用os.system("clear")不断更新屏幕,然后每隔几秒打印一个不同的文本消息.如何在循环期间获得用户输入?raw_input()只是暂停和等待,这不是我想要的功能.
import os
import time
string = "the fox jumped over the lazy dog"
words = string.split(" ")
i = 0
while 1:
os.system("clear")
print words[i]
time.sleep(1)
i += 1
i = i%len(words)
Run Code Online (Sandbox Code Playgroud)
我希望能够在中间按'q'或'p'分别退出和暂停.
我目前正在学习CodeIgniter PHP框架.目前,我正在寻找DEV环境和PRODUCTION环境.来自纯粹的C和JAVA背景,我习惯在本地拥有所有东西(带版本控制),但由于我将在网站上有PRODUCTION方面,我想知道几件不同的事情:
我很感激您提前提出的任何想法或建议.
谢谢!
如何使用Authorization API将用户权限提升为root,以便可以使用mach_inject?
以下代码工作正常.它显示一个panedwindow,顶部有一个蓝色框,下面是一个绿色框:
panedwindow .root -orient vertical -showhandle true -background red
frame .top -background blue -width 100 -height 100
frame .bot -background green -width 100 -height 100
.root add .top .bot
pack .root -expand true -fill both
Run Code Online (Sandbox Code Playgroud)
但是,当我panedwindow向下移动命令时,事情就会停止工作.顶部的蓝色框未显示.相反,panedwindow它本身的红色闪耀着:
frame .top -background blue -width 100 -height 100
panedwindow .root -orient vertical -showhandle true -background red
frame .bot -background green -width 100 -height 100
.root add .top .bot
pack .root -expand true -fill both
Run Code Online (Sandbox Code Playgroud)
为什么会这样?可以将panedwindow真的只管理后创建的小部件?我已经看到了与打包器类似的行为,它将拒绝打包-in …
c# ×3
.net ×1
c ×1
c89 ×1
codeigniter ×1
frameworks ×1
javascript ×1
macos ×1
mocking ×1
ninject ×1
php ×1
python ×1
strcpy ×1
strncpy ×1
tcl ×1
tk-toolkit ×1
unit-testing ×1
wcf ×1