我以前没有真正使用过按位枚举,我只是想确保我的测试是正确的.我最感兴趣的是测试值None和All.我们从使用此枚举的Web服务接收数据,以对某些数据进行分类.鉴于此,我假设nether None和All将与任何其他值组合.
给出以下按位枚举定义;
[System.FlagsAttribute()]
public enum TrainingComponentTypes : int
{
None = 0,
AccreditedCourse = 1,
Qualification = 2,
Unit = 4,
SkillSet = 8,
UnitContextualisation = 16,
TrainingPackage = 32,
AccreditedCourseModule = 64,
All = 127,
}
Run Code Online (Sandbox Code Playgroud)
我在这个MSDN网站上阅读了关于FlagAttributes 的以下引用;
使用None作为其值为零的标志枚举常量的名称.您不能在按位AND运算中使用None枚举常量来测试标志,因为结果始终为零.但是,您可以在数值和None枚举常量之间执行逻辑而非按位比较,以确定是否设置了数值中的任何位.
此实例中的逻辑比较是否指向枚举的正常相等性测试?例如;
TrainingComponentTypes tct = TrainingComponentTypes.None;
if (tct == TrainingComponentTypes.None)
{ ... }
Run Code Online (Sandbox Code Playgroud)
为了进行逐位比较,我正在执行以下操作;
TrainingComponentTypes tct = TrainingComponentTypes.AccreditedCourse | TrainingComponentTypes.Qualification | TrainingComponentTypes.TrainingPackage;
Assert.IsTrue((tct & TrainingComponentTypes.AccreditedCourse) == TrainingComponentTypes.AccreditedCourse, "Expected AccreditedCourse as part the enum");
Assert.IsFalse((tct …Run Code Online (Sandbox Code Playgroud) 我们遇到了一个问题,我们的一个存储过程抛出错误;
SELECT failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'
Run Code Online (Sandbox Code Playgroud)
我通过修改存储的proc并将引用的标识符设置为ON来修复它.问题是,我在CREATE PROCEDURE调用之前做了这个.例如;
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[InsertStuff]
Run Code Online (Sandbox Code Playgroud)
我原以为这会影响CREATE PROCEDURE语句,但不会影响该程序的执行.
我们的脚本都被部署为drop并创建脚本并通过sqlcmd运行.我刚刚在这里阅读(搜索示例:执行SQLCMD),这里 sqlcmd执行时带引号标识符off.我已经更改了我们的脚本以包含-I开关,以查看是否可以解决我们的问题.
那时我的问题是;
1)SET QUOTED_IDENTIFIER ON语句是否仅影响DDL CREATE PROCEDURE语句,还是它也影响存储过程的执行?我的快速测试表明后者.
2)由于此开关的默认设置为ON,我假设通过设置-I我的sqlcmd查询的开关将没有不利影响.对于所有意图和目的,我将假设它与复制脚本的内容然后将它们粘贴到查询管理器并执行命令相同.如果我错了,请纠正我.我们的简单部署脚本如下;
@echo off
SET dbodir=../Schema Objects/Schemas/dbo/Programmability/Stored Procedures/
SET tpmdir=../Schema Objects/Schemas/TPM/Programmability/Stored Procedures/
echo --- Starting dbo schema
for %%f in ("%dbodir%*.sql") do (echo Running %%f.... && @sqlcmd -I -U %1 -P %2 -S %3 -d %4 -i …Run Code Online (Sandbox Code Playgroud) 我试图从C#调用一个C DLL,但我没有任何快乐.DLL的文档提供了VB的示例函数delaration,看起来像;
Declare Function TransGeogPt Lib "c:\DLLS\GDAit.dll" (ByVal sGridFile As String, ByVal lDirection As
Long, ByVal dLat As Double, ByVal dLong As Double, pdLatNew As Double, pdLongNew As Double,
pdLatAcc As Double, pdLongAcc As Double) As Long
Declare Function TransProjPt Lib "c:\DLLS\GDAit.dll" (ByVal sGridFile As String, ByVal lDirection As
Long, ByVal dLat As Double, ByVal dLong As Double, ByVal lZone As Long, pdLatNew As Double,
pdLongNew As Double, pdLatAcc As Double, pdLongAcc As Double) As Long
Run Code Online (Sandbox Code Playgroud)
因此我做了以下事情;
public class GDAIt …Run Code Online (Sandbox Code Playgroud) 我试图将DateTime.MinValue转换为DateTimeOffset值,但我得到一个ArgumentOutOfRange异常.
我正在查看关于DateTime到DateTimeOffset的隐式转换的MSDN文章,而Exception部分声明我将收到此ArgumentOutOfRange异常;
...应用偏移量产生的协调世界时(UTC)日期和时间早于MinValue....
那么为什么以下代码会抛出异常;
DateTime test = DateTime.MinValue;
DateTimeOffset dto = test;
Run Code Online (Sandbox Code Playgroud)
这仅仅是因为我的时区吗?我在GMT +8,但我对上述代码的理解是测试是使用Unspecified类型创建的.
我正在解决这个问题,只需测试我的DateTime的MinValue,如果是的话,那么使用DateTimeOffset.MinValue代替.
我只是好奇为什么我的未指定的类DateTime对象导致错误.
我觉得这很愚蠢,但是因为我不知道答案,所以我还是继续前进.
我正在尝试一些身份验证代码,并想知道为什么我从Rfc2898DeriveBytes获得的字节数组需要转换为HEX并再次返回到字节数组,以便正确初始化我的HMACSHA1对象.我觉得我做的事情很傻,或者只是遗漏一些明显的东西
我的客户端代码是基于crypto-js的javascript函数;
var key256bit = Crypto.PBKDF2(passwordEntered, saltBytes, 32, { iterations: 1000 });
var hmacBytes = Crypto.HMAC(Crypto.SHA1, url, key256bit, { asBytes: true });
var base64Hash = Crypto.util.bytesToBase64(hmacBytes);
Run Code Online (Sandbox Code Playgroud)
我的服务器端代码如下;
Rfc2898DeriveBytes rfc2898 = new Rfc2898DeriveBytes(password,
encoding.GetBytes(salt), 1000);
byte[] key = rfc2898.GetBytes(32);
// Don't think I should need to do this.
// However, it wont work if I initialise HMACSHA1
// with the rfc2898.GetBytes(32)
string test = ByteArrayToString(key);
HMACSHA1 hmacSha1 = new HMACSHA1(encoding.GetBytes(test));
byte[] computedHash = hmacSha1.ComputeHash(encoding.GetBytes(requestUri));
string computedHashString = Convert.ToBase64String(computedHash); …Run Code Online (Sandbox Code Playgroud) 我需要在两个数据库表中的数据之间提供建议的匹配.基本要求是; - 对于所讨论的两列之间的最大匹配单词数(不论顺序),应建议"匹配".
例如,给定数据;
Table A Table B
1,'What other text in here' 5,'Other text in here'
2,'What am I doing here' 6,'I am doing what here'
3,'I need to find another job' 7,'Purple unicorns'
4,'Other text in here' 8,'What are you doing in here'
Ideally, my desired matches would look as follows;
1 -> 8 (3 words matched)
2 -> 6 (5 words matched)
3 -> Nothing
4 -> 5 (4 words matched)
Run Code Online (Sandbox Code Playgroud)
我发现字数统计函数看起来很有希望,但我想不出如何在SQL语句中使用它,这将给我我想要的匹配.此外,链接的函数不是我需要的,因为它使用charindex,我认为在单词中搜索单词(即'in'将匹配'bin').
任何人都可以帮我解决这个问题吗?
谢谢.
我的.gitignore文件包含以下条目.我在这里尝试多种方法,因为我似乎无法忽略我的文件;
WinAppSetup/*.exe
/WinAppSetup/*.exe
WinAppSetup/setup.exe
**/WinAppSetup/setup.exe
Run Code Online (Sandbox Code Playgroud)
当我git status从git bash 运行时,我仍然看到;
modified: WinAppSetup/setup.exe
Run Code Online (Sandbox Code Playgroud)
我的.gitignore中的哪些条目允许我忽略此文件?
在编辑.gitignore之后,我是否需要关闭并重新打开git bash才能重新读取.gitignore文件?
UPDATE
根据user2407038的评论,问题是该文件已经存在于存储库中.我能够在本地删除文件,暂存,然后提交这些更改并更新我的遥控器.然后,应用程序的新版本成功忽略该文件.
看来我也可以更新我的.gitignore文件,而不必关闭并重新打开git bash.
我想尝试比较两种类型的DateTime相对干净的方法?对象无需烦扰大量的空检查.
以下是一个好主意,或者有一个更简单或明智的方法来实现它;
DateTime? test = DateTime.MinValue;
DateTime? date1 = new DateTime(2008, 6, 1, 7, 47, 0);
if (string.Format("{0:MM/dd/yyyy}", date1) == string.Format("{0:MM/dd/yyyy}", test))
{
Console.WriteLine("They are the same");
}
else
{
Console.WriteLine("They are different");
}
Run Code Online (Sandbox Code Playgroud)