我想将值存储为键,值,值对.我的数据类型
Key -> int & both values -> ulong,
Run Code Online (Sandbox Code Playgroud)
如何初始化和获取此类字典的值.我正在使用VS-2005.
如果我使用类或结构,那么我如何获取值.
当dropdownlist值为,yes并且字段必须为date 时,我正在尝试使用FluentValidation validaton .当dropdownlist yes检查时它正在工作date.但是当我选择No它时,它也会显示验证Must be date.
它应该不再验证是否下拉列表值除了yes.我们怎么做?
RuleFor(x => x.DtPublishedTimeText)
.NotEmpty()
.When(HasMaterialPublishedElseWhereText)
.WithMessage("Required Field")
.Must(BeAValidDate)
.WithMessage("Must be date");
private bool BeAValidDate(string val)
{
DateTime date;
return DateTime.TryParse(val, out date);
}
private bool HasMaterialPublishedElseWhereText(MeetingAbstract model)
{
return model.HasMaterialPublishedElseWhereText != null &&
model.HasMaterialPublishedElseWhereText.Equals("yes");
}
Run Code Online (Sandbox Code Playgroud) 我正在探索Silverlight附加的行为机制,以便在我的Silverlight应用程序中使用Model-View-ViewModel模式.首先,我试图让一个简单的Hello World工作,但我完全陷入了一个我无法找到解决方案的错误.
我现在拥有的是一个只包含一个按钮的页面,该按钮在单击时应显示一条消息.通过使用从Behavior派生的类来处理click事件,并将消息指定为行为本身的依赖项属性.当尝试将message属性绑定到用作数据上下文的viewmodel类的属性时出现问题:我InitializeComponent在视图中的调用中获得了一个exeption .
这是我正在使用的所有代码,因为您可以看到它非常简单.首先是主页面的标记及其包含的视图:
我的页面
<UserControl x:Class="MyExample.MyPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyExample"
>
<Grid x:Name="LayoutRoot">
<local:MyView/>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
MyView(TextBlock只是检查绑定语法是否正确)
<UserControl x:Class="MyExample.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:local="clr-namespace:MyExample"
Width="400" Height="300">
<StackPanel Orientation="Vertical" x:Name="LayoutRoot" Background="White">
<StackPanel.Resources>
<local:MyViewmodel x:Key="MyResource"/>
</StackPanel.Resources>
<TextBlock Text="This button will display the following message:"/>
<TextBlock Text="{Binding MyMessage, Source={StaticResource MyResource}}" FontStyle="Italic"/>
<Button x:Name="MyButton" Content="Click me!">
<i:Interaction.Behaviors>
<local:MyBehavior Message="{Binding MyMessage, Source={StaticResource MyResource}}"/>
</i:Interaction.Behaviors>
</Button>
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
现在代码中有两个类:一个用于行为,另一个用于viewmodel:
MyViewmodel
public class MyViewmodel
{
public string MyMessage
{
get { return "Hello, world!"; …Run Code Online (Sandbox Code Playgroud) 我已经开始为旧的基于Z80的机器开发SMB服务器.这台机器运行一个非常简单的,类似MS-DOS的操作系统(没有多任务,没有用户的概念,只有FAT文件系统,没有unicode,只有8.3文件名)并且内存有限,因此我的第一个想法就是只实现SMB核心协议.我将使用TCP传输.
至于现在,我只有一个非常短的测试代码,只是回复SMB_COM_NEGOTIATE命令,表明核心协议("PC NETWORK PROGRAM 1.0")是所需的方言.为了测试它,我尝试通过打开资源管理器窗口并输入"\\<server IP>"地址栏从Windows 7计算机连接.我已经与Wireshark验证了服务器收到协商命令并发送(显然)正确的响应.
问题:一旦Windows客户端收到响应,它就会显示一个通用的"无法访问资源"错误消息(错误代码为0x80004005),然后没有任何反应(不再发送SMB消息).我期待收到SMB_COM_TREE_CONNECT或类似的命令.
我在想,也许Windows 7不支持核心协议(它很老,而且它没有任何安全功能),但是,为什么它会在协商请求中列出核心方言名称?也许我错过了一些步骤?服务器必须在协商响应后发送任何其他数据包吗?
客户端操作系统是Windows 7 Ultimate 64位,以下是请求和响应的Wireshark转储,以防任何人在此过程中发现任何错误:
请求:

响应:

更新:如果我选择NT LM 0.12方言而不是核心方言,我会从客户端收到一个SESSION_SETUP_AND_REQUESTX命令.显然,似乎确实,Windows 7不支持核心协议.无论如何,任何额外的信息都将受到赞赏.
我有2个Linq2Sql类:Parent和Child.我想做一些事情,比如删除父母的所有孩子,或更新所有子记录.在SQL中我会写:
delete Child where ParentID = @p
Run Code Online (Sandbox Code Playgroud)
要么
update Child set Val = Val+1 where ParentID = @p
Run Code Online (Sandbox Code Playgroud)
我可以在Linq中以蛮力的方式在Parent课堂内这样做:
Children.ToList().ForEach(c => c.DeleteOnSubmit()); // DeleteOnSubmit is my own method
Run Code Online (Sandbox Code Playgroud)
和
Children.ToList().ForEach(c => c.Val++);
Run Code Online (Sandbox Code Playgroud)
但鉴于Linq对ForEach循环的固有性能损失,这似乎是一种非常低效的方法.是否有某种方法可以实现所需的结束,只会触发一个查询?
使用String.Concat(Object)而不是String.Concat(String)在C#中的目的是什么?为什么不使用隐式调用Object.ToString()而不是传递object自己也可能导致拳击发生?
Int32 i = 5;
String s = "i = ";
// Boxing happens, ToString() is called inside
Console.WriteLine(s + i);
// Why compiler doesn't call ToString() implicitly?
Console.WriteLine(s + i.ToString());
Run Code Online (Sandbox Code Playgroud)
给我们以下IL.
.method private hidebysig static void MyDemo() cil managed
{
// Code size 47 (0x2f)
.maxstack 2
.locals init ([0] int32 i, [1] string s)
IL_0000: nop
IL_0001: ldc.i4.5
IL_0002: stloc.0
IL_0003: ldstr "i = "
IL_0008: stloc.1
IL_0009: ldloc.1
IL_000a: …Run Code Online (Sandbox Code Playgroud) 所以我发布了几次,以前我的问题很模糊
我本周开始使用C++,并且做了一个小项目
所以我试图计算标准偏差和方差
我的代码加载一个100个整数的文件,并将它们放入一个数组,计算它们,计算平均值,总和,var和sd
但我的方差有点麻烦
我不断得到一个巨大的数字 - 我感觉它与它的计算有关
我的意思和总和还可以
任何帮助或提示?
注意:
干杯,
插口
using namespace std;
int main()
{
int n = 0;
int Array[100];
float mean;
float var;
float sd;
string line;
float numPoints;
ifstream myfile(“numbers.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline(myfile, line);
stringstream convert(line);
if (!(convert >> Array[n]))
{
Array[n] = 0;
}
cout << Array[n] << endl;
n++;
}
myfile.close();
numPoints = n;
}
else cout<< "Error loading file" <<endl;
int sum = accumulate(begin(Array), end(Array), 0, …Run Code Online (Sandbox Code Playgroud) 我有一个关于RouteLink与ActionLink的问题.
请考虑以下路线
routes.MapRoute("Routename1",
"{someEnum}/SpecificAction/{id}/{stringId}",
new { controller = "MyController", id = (int?)null, stringId= (string)null, action = "SpecificAction" },
new { someEnum= "(EnumVal1|EnumVal2)" }
);
Run Code Online (Sandbox Code Playgroud)
奇怪的{someEnum}部分是因为我对枚举的所有值使用通用控制器,它构成了url的典型控制器部分.例如,/ EnumVal1/Action /和/ EnumVal2/Action /使用相同的控制器.然而,这不是问题的一部分.
考虑以下两种链接方式:
<%=Html.RouteLink("Click me","Routename1", new { id = 32, stringId = "Yatzy" })%>
<%=Html.ActionLink("Click me", "SpecificAction", "EnumVal1", new { id = 32, stringId = "Yatsy" }, null)%>
Run Code Online (Sandbox Code Playgroud)
RouteLink生成正确的URL,即/ EnumVal1/SpecificAction/32/Yatzy
ActionLink生成一个类似于/ EnumVal1/SpecificAction/32的URL?stringId = Yatzy
为什么是这样?请有人向我解释一下.
我正在使用v3 API并设法列出repos/trees/branches,访问文件内容以及创建blob/trees/commit.我现在正在尝试创建一个新的repo,并设法用"POST user/repos"来做
但是当我尝试在这个新的repo中创建blob/trees/commits/references时,我得到了相同的错误消息.(409)"Git Repository是空的." 显然,我可以通过git命令行自己启动存储库,但是如果我的应用程序为我做了它,我宁愿这样做.
有没有办法做到这一点?在创建空存储库后,我需要通过API做的第一件事是什么?
谢谢
好的,所以我非常清楚如何在Unity3d中使用协同例程,但我想为延迟执行创建一个可重用的组件,这样我就可以像这样使用代码
StartCoroutine(WaitForDamageCooldown(DamageCooldown));
IEnumerator WaitForDamageCooldown(float duration)
{
yield return new WaitForSeconds(duration);
HasTempInvincibility = false;
}Run Code Online (Sandbox Code Playgroud)
把它转换成这样的东西
CoroutineUtil.DeferredExecutor(float waitTime,Action onComplete);Run Code Online (Sandbox Code Playgroud)
要像这样使用
StartCoroutine(CoroutineUtil.DeferredExecutor(WaitTime, () =>
{
Debug.Log("DeferredExecutor wait complete");
HasTempInvincibility = false;
}));Run Code Online (Sandbox Code Playgroud)
我已尝试在以下实现
using System;
using System.Collections;
using UnityEngine;
public static class CoroutineUtil
{
public static IEnumerator DeferredExecutor(float waitDuration, Action onComplete)
{
yield return new WaitForSeconds(waitDuration);
onComplete.Invoke();
}
public static IEnumerator DeferredExecutor<T>(float waitDuration, T obj, Action<T> onComplete)
{
yield return new WaitForSeconds(waitDuration);
onComplete.Invoke(obj);
}
}Run Code Online (Sandbox Code Playgroud)
我认为这可能无法作为静态工作我也试图将它添加到对象的类中
public class Player: MonoBehaviour
{
///....etc …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×3
asp.net-mvc ×2
actionlink ×1
api ×1
arrays ×1
average ×1
boxing ×1
c++ ×1
clr ×1
coroutine ×1
dictionary ×1
github ×1
github-api ×1
linq ×1
linq-to-sql ×1
repository ×1
routes ×1
silverlight ×1
smb ×1
string ×1
variance ×1
windows-7 ×1