我目前正在.Net Framework 2.0中用C#重写旧的VB6程序(不是我的选择,它是由公司决定的).在大多数情况下,事情进展顺利.该程序测量来自精密磨床的输入数据,并显示图形和刻度盘以显示精度.
最初的程序员是机械工程师,但不是软件工程师.该程序有效,但这里和那里有一些草率的代码.最值得注意的是,我遇到了一些GoTo语句.在必要时将事物放在一个循环中并且从中获得相同的功能非常容易.
我遇到了原始代码中的一个案例,然而,似乎GoTo不仅仅是模拟一个循环.它有几个不同的退出条件.它看起来像这样(不是实际的代码,只是我做的简短演示):
VB6代码
Public Sub Tick()
Dim condition1 As Boolean
Dim condition2 As Boolean
Dim testNumber As Integer
beginning: 'The GoTo label'
' (... Some Other Code Here ...)'
If condition1 = True Then
goto beginning
Else
' (... Do some calculation ...)'
End If
If condition2 = True Then
' (... Do some calculation ...)'
goto beginning
End If
Select Case testNumber
Case 1: '(... Some code ...)'
Case 2: '(... Some code ...)'
Case 3: …Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码从远程ftp服务器下载文件:
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverPath);
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(userName, password);
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
using (StreamWriter destination = new StreamWriter(destinationFile))
{
destination.Write(reader.ReadToEnd());
destination.Flush();
}
Run Code Online (Sandbox Code Playgroud)
我正在下载的文件是一个DLL,我的问题是它以某种方式被这个过程改变了.我知道这是因为文件大小正在增加.我怀疑这部分代码是错误的:
destination.Write(reader.ReadToEnd());
destination.Flush();
Run Code Online (Sandbox Code Playgroud)
任何人都可以提出任何可能出错的想法吗?
我有一个简单的查询,我想知道它是否可以更优雅地编码.最终解决方案必须符合ansi标准.
我需要根据日期和版本从表中获取最新值.样本会更清楚地解释:
declare @t table (id int, due_date smalldatetime, version int, value nvarchar(10))
insert into @t select 3, '1/1/2010', 1, 'value 1'
insert into @t select 3, '1/1/2010', 2, 'value 2'
insert into @t select 3, '3/1/2010', 1, 'value 3'
insert into @t select 3, '3/1/2010', 2, 'value 4'
insert into @t select 3, '3/1/2010', 3, 'value 5'
insert into @t select 3, '3/1/2010', 4, 'value 6'
insert into @t select 3, '4/1/2010', 1, 'value 7'
insert into @t select …Run Code Online (Sandbox Code Playgroud) 我已阅读并且我相信我理解C#的using语句是什么(如果我错了请纠正我):将IDisposable对象初始化为只读有限范围(using块).我知道你可以在之前初始化using并且不限制范围,但建议不要这样:
http://msdn.microsoft.com/en-us/library/yh598w02.aspx
我并不总是关注哪些类是什么类的子类.我不太确定哪些类继承自IDisposable.我不只是好奇在一个using语句中可以使用哪些类,但是我的同事希望在一个using块中找到哪些类?块中应该包含哪些类using?另外,没有使用using块而不调用Dispose 有什么问题吗?它只是关于记忆还是稳定?
我有一个布尔函数,用于许多其他函数的决策.并且每次都向用户提供消息框或允许其继续,具体取决于该函数的返回值.所以我的伪代码可能如下所示:
private bool IsConsented()
{
//some business logic
}
private void NotReal()
{
if (IsConsented())
{
//call function A
}
else
{
MessageBox.Show("Need consent first.");
}
}
private void NotReal2()
{
if (IsConsented())
{
//call function B
}
else
{
MessageBox.Show("Need consent first.");
}
}
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种更简单的方法,而不是将if-else逻辑硬编码到我的每个函数中.我希望能够有这样的功能:
private void CheckConsent(function FunctionPointer)
{
if (IsConsented())
{
//call the function
FunctionPointer();
}
else
{
MessageBox.Show("Need consent first.");
}
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以将指针传递给函数.我真的怀疑这与委托有关,但我不知道语法,我不明白如何使用委托传递参数.
我想使用公钥加密系统将非常少的数据(确切地说是15个字节)加密到尽可能短(最佳,不超过16个字节)的消息.
遗憾的是,标准公钥系统RSA产生与其密钥一样大的消息,大约100字节,具体取决于密钥大小.为了使事情变得更加困难,我只能使用.NET框架库,即没有第三方.
我已经在维基百科中阅读了一些关于椭圆曲线加密的内容,并且文本似乎表明其中的密钥大小通常比RSA密钥短得多.
这是否也转换为短信息?可以使用.NET ECDiffieHellmanCng类来解密/加密消息吗?它似乎具有不同的类结构,比如RSA或对称密码.
#! /usr/local/bin/perl
sub getClusters
{
my @clusters = `/qbo/bin/getclusters|grep -v 'qboc33'`;
chomp(@clusters);
return \@clusters;
}
Run Code Online (Sandbox Code Playgroud)
嗯好吧..我怎么得到这个阵列打印,因为......
foreach $cluster (getClusters())
{ print $cluster."\n"; }
Run Code Online (Sandbox Code Playgroud)
似乎不起作用.谢谢.
我想要完成的一个很好的例子是在最新版本的Spotify iPhone应用程序中实现的(Pandora似乎具有相同的功能).
当Spotify在后台时,双击可打开"多任务停靠",其中ipod控件(播放/暂停,转发等)允许控制Spotify(不是ipod应用程序)的音乐播放.此外,当iphone/ipod touch被锁定时,双击会显示类似的播放控件.
如果你不知道我的意思,这里有一篇截图的文章:http: //www.wired.com/gadgetlab/2010/07/spotify-updated-for-ios4-ready-to-replace-ipod/
在我目前的应用程序中,音乐是从服务器流式传输的(使用Matt Gallagher的AudioStreamer).我设法让音乐在后台播放.现在,我想将我的播放链接到"多任务停靠"/锁定屏幕.
我应该用[MPMusicPlayerController iPodMusicPlayer]吗?我该怎么办?
额外的问题:如果你能告诉我如何在"多任务停靠"中将ipod图标更改为我的应用程序图标(Spotify也提取了这个技巧......),这真是太棒了.
任何帮助表示感谢,谢谢.
如何创建简单的javascript/jquery客户端验证码?
如果是这样,它是什么?
编辑:回应下面的评论:
var tabulatedOutputErrors = from error in outputErrors
group error by error into errorGroup
select new { error = errorGroup.Key, number = errorGroup.Count() };
var tabulatedInputErrors = from error in inputErrors
group error by error into errorGroup
select new { error = errorGroup.Key, number = errorGroup.Count() };
var problems = tabulatedOutputErrors.Except(tabulatedInputErrors);
Run Code Online (Sandbox Code Playgroud)
如果需要,您可以扩展计数.