我做了一个非常简单的代表节目.我不知道为什么它显示错误,即使我将它与MSDN库中给出的相比,它与MSDN中的相同,仍然没有被编译..错误说 - "名称'添加'不存在在当前的上下文中"和其他方法相同..减去.请帮我查一下有什么问题..
namespace DelegatePrac
{
public delegate void One(int a, int b);
public class Some
{
static void Add(int a, int b)
{
int c = a + b; Console.WriteLine("{0}",c);
}
static void Subtract(int a, int b)
{ int c = a - b; Console.WriteLine("{0}",c);
}
}
class Program
{
static void Main(string[] args)
{
One o1,o2;
o1 = Add;//gives error here
o2 = Subtract;//and here!!
o1(33,44);
o2(45, 15);
Console.ReadLine();
}
}
}Run Code Online (Sandbox Code Playgroud)
我正在关注此链接 - http://msdn.microsoft.com/en-us/library/ms173175.aspx
谢谢
我正在尝试使用Maven在运行某些集成测试之前启动应用程序.我在Windows上.我的Maven插件配置如下所示:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>start-my-application</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>start_application.bat</executable>
<workingDirectory>./path/to/application</workingDirectory>
</configuration>
</execution>
<executions>
<plugin>
Run Code Online (Sandbox Code Playgroud)
我的批处理文件如下所示:
start myApplication.exe
Run Code Online (Sandbox Code Playgroud)
在隔离运行时,批处理文件会生成一个单独的窗口来运行应用程序并立即返回控制.
但是,从Maven运行时,构建会在继续之前等待单独窗口中的进程完成.这在某种程度上打败了集成测试阶段......
我有什么想法可以在Maven中启动一个真正独立的过程,以便让构建继续与它一起继续吗?
使用C/C++,getopt_long()可用于解析命令行参数.是否有可能告诉函数某些选项是强制性的?例如,getopt_long如果startServer在不提及下面的端口的情况下调用,我怎么能告诉解析应该给出错误?
./startServer -port 80
注意:我不是说选项参数是强制性的,而是选项本身.
我正在寻找一个简单的解决方案,通过按下删除键删除NSTableView行.我在谷歌搜索时看到的就是这样的答案:http://likethought.com/lockfocus/2008/04/a-slightly-improved-nstableview/.这在我看来是一个工程解决方案,但我想知道这是否是最好的方法.有人知道更好的答案吗?
我正在尝试用 Java 制作一个 mp3 播放器,但我不知道如何控制其中的音量。
我试过这样的事情:
// Adjust the volume on the output line.
if (dataLine.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
FloatControl volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(100.0F);
}
Run Code Online (Sandbox Code Playgroud)
在这段代码工作正常之前,我编写的所有内容都很好,但显然 dataLine 不受支持,因为它跳过了这个 IF 语句。
我的问题是:你知道为什么会发生这种情况吗,我该如何解决这个问题,以便我可以控制我的应用程序的音量?
我想以编程方式发送电子邮件.
我尝试了以下代码.
最终Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
Run Code Online (Sandbox Code Playgroud)emailIntent.setType("plain/text"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "abc@gmail.com" }); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Email Subject"); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Email Body"); startActivity(Intent.createChooser( emailIntent, "Send mail..."));
但问题是在发送电子邮件之前应用程序打开活动

我想直接发送电子邮件而不需要开放撰写活动.这怎么可能?
我想要实现的目标如下:同事在@coworkers组,客户在@clients组.
Git仓库应该可以为每个人读写,但是应该有特殊的分支.即我创建一个新的分支"实习生"和@coworkers应该有RW + access,但客户端不应该能够R或W.
我以为我能做到这一点
repo myrepo
- intern = @clients
RW+ = @clients @coworkers
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
基本上,我有以下代码(在此解释:协议中的Objective-C常量)
// MyProtocol.m
const NSString *MYPROTOCOL_SIZE;
const NSString *MYPROTOCOL_BOUNDS;
@implementation NSObject(initializeConstantVariables)
+(void) initialize {
if (self == [NSObject class])
{
NSString **str = (NSString **)&MYPROTOCOL_SIZE;
*str = [[MyClass someStringLoadedFromAFile] stringByAppendingString:@"size"];
str = (NSString **)&MYPROTOCOL_BOUNDS;
*str = [[MyClass someStringLoadedFromAFile] stringByAppendingString:@"bounds"];
}
}
@end
Run Code Online (Sandbox Code Playgroud)
我想知道:有一个覆盖NSObject +initialize方法的类别对我来说安全吗?
在运行应用程序测试时(即在设备上),我的OCUnit测试套件出现了一些问题.偶尔,我会收到一个似乎从OCUnit类抛出的棘手错误.我一直在试图查看添加到测试套件中的文件,但无法理解它.
我在设置测试目标时遵循了Apple文档并查看了其他教程,从而产生了以下目标(以及缩进的依赖项):
LogicTests
MyApp LogicTests
ApplicationTests MyApp
MyAppTesting ApplicationTests
最后一个(MyAppTesting)是我在设备上运行以启动测试套件的那个.
如上所述,测试无法启动有时会在控制台中抛出以下输出:
2010-11-17 12:02:48.537 VCCTesting[12018:307] *** Assertion failure in -[SenTestClassEnumerator init], /SourceCache/OCUnit/OCUnit-1685/SourceCode/SenTestingKit/SenTestClassEnumerator.m:137
2010-11-17 12:02:48.556 VCCTesting[12018:307] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'objc_getClassList returned more classes than it should have.'
*** Call stack at first throw:
(
0 CoreFoundation 0x30897ed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x3002f811 objc_exception_throw + 24
2 CoreFoundation 0x30897d15 +[NSException raise:format:arguments:] + 68
3 Foundation 0x349f932f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 62
4 SenTestingKit 0x20107c29 -[SenTestClassEnumerator init] + …Run Code Online (Sandbox Code Playgroud) 我正在尝试将列表导出为CSV文件.我完成了所有工作,我想写入文件到响应流.这没有任何作用.
这是我的代码:
从页面调用方法.
$('#btn_export').click(function () {
$.post('NewsLetter/Export');
});
Run Code Online (Sandbox Code Playgroud)
控制器中的代码如下:
[HttpPost]
public void Export()
{
try
{
var filter = Session[FilterSessionKey] != null ? Session[FilterSessionKey] as SubscriberFilter : new SubscriberFilter();
var predicate = _subscriberService.BuildPredicate(filter);
var compiledPredicate = predicate.Compile();
var filterRecords = _subscriberService.GetSubscribersInGroup().Where(x => !x.IsDeleted).AsEnumerable().Where(compiledPredicate).GroupBy(s => s.Subscriber.EmailAddress).OrderBy(x => x.Key);
ExportAsCSV(filterRecords);
}
catch (Exception exception)
{
Logger.WriteLog(LogLevel.Error, exception);
}
}
private void ExportAsCSV(IEnumerable<IGrouping<String, SubscriberInGroup>> filterRecords)
{
var sw = new StringWriter();
//write the header
sw.WriteLine(String.Format("{0},{1},{2},{3}", CMSMessages.EmailAddress, CMSMessages.Gender, CMSMessages.FirstName, CMSMessages.LastName));
//write every subscriber to …Run Code Online (Sandbox Code Playgroud)