goto在这段代码中使用是否正确?还有其他选择吗?
return ExecuteReader(cmd, reader =>
{
List<BEPartnership> partnerhip = null;
//Partnership
if (!((SqlDataReader) reader).HasRows)
goto exit;
partnerhip =
new List<BEPartnership>{new BEPartnership().GetFromReader(reader)};
//Customers
if (!reader.NextResult() && !((SqlDataReader) reader).HasRows)
goto exit;
foreach (BEPartnership p in partnerhip)
p.Partner = new BECustomer().GetFromReader(reader);
//Contracts
if (!reader.NextResult() && !((SqlDataReader) reader).HasRows)
goto exit;
List<BEContractB2B> contracts = new List<BEContractB2B>();
contracts.Add(new BEContractB2B().GetFromReader(reader));
// contracts = new BEContractB2B().GetFromReader2(reader).ToList();
exit:
return partnerhip;
});
Run Code Online (Sandbox Code Playgroud) var a = MyClassInstance;
MyClassInstance = null;
//if (a !=null){ //why }
Run Code Online (Sandbox Code Playgroud)
我认为a指向MyClassInstance和MyClassInstance等于null,那么也a必须等于null.但a不是空的,我不明白为什么.
有 2 个音频(mp3 或 wav)文件。第一个文件是我的声音,第二个文件是我朋友的声音。他们每个人都有10 秒的持续时间。我想将它们结合起来得到一个文件,它也应该有 10 秒的持续时间。
我应该使用哪些工具或实用程序来解决这个问题?
更新:我使用了 lame.exe,但它连接了它们并创建了持续时间为 20 秒的文件。
我试图在我的一个上下文菜单项中添加一个图标,但我无法做到.有谁能够帮我?
这是我写的代码:
private System.Windows.Forms.ContextMenu notifyContextMenu;
private void foo() {
if (notifyIcon == null) {
notifyIcon = new System.Windows.Forms.NotifyIcon();
}
if (notifyContextMenu == null) {
notifyContextMenu = new System.Windows.Forms.ContextMenu();
notifyContextMenu.MenuItems.Add("Exit");
// How do I add an icon to this context menu item?
}
notifyIcon.ContextMenu = notifyContextMenu;
}
}
Run Code Online (Sandbox Code Playgroud) 我是一名ASP.NET MVC开发人员,他决定学习Ruby和Ruby on Rails.我已经知道了什么,并在RoR上创建了一个网站.在ASP.NET MVC上开发,我一直使用三层架构:数据层,业务层和UI(或表示)层.
试图在Ruby on Rails应用程序中使用这种方法,我发现没有关于它的信息(或者我可能找不到它?).
也许有人可以建议我如何在Ruby on Rails上创建或使用三层架构?
PS我使用ruby 1.9.3和Ruby on Rails 3.2.3.
在 Ruby on Rails 应用程序中存储配置值(密钥、密码或仅配置值)的最佳位置在哪里?我搜索了很多,但没有找到我认为正确的答案。
class MainController < ApplicationController
@my_var = 123
def index
var1 = @my_var
end
def index2
var2 = @my_var
end
end
Run Code Online (Sandbox Code Playgroud)
为什么两者var1都不var2相等123?
我正在尝试通过RSpec测试我的Rails 3.2.3应用程序.它已安装(我已经测试了另一个应用程序并且运行良好)但它在Gemfile中不存在.这是代码spec/application_controller_spec.rb
require "rspec"
require_relative "../app/controllers/application_controller"
describe ApplicationController do
it "current_cart does something" do
#app_controller = ApplicationController.new
pending
end
end
Run Code Online (Sandbox Code Playgroud)
以下命令返回错误:
alex@ubuntu:~/RubymineProjects/psg$ rspec spec
/home/alex/RubymineProjects/psg/app/controllers/application_controller.rb:1:in `<top (required)>': uninitialized constant ActionController (NameError)
from /home/alex/RubymineProjects/psg/spec/application_controller_spec.rb:2:in `require_relative'
from /home/alex/RubymineProjects/psg/spec/application_controller_spec.rb:2:in `<top (required)>'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
Run Code Online (Sandbox Code Playgroud)
文件ApplicationController.rb
class ApplicationController < ActionController::Base
def some_action
#............
end
Run Code Online (Sandbox Code Playgroud)
结束
即使我添加gem 'rspec'Gemfile也不会改变任何内容,错误仍然存在.
有什么想法吗?
在Mongoid中是否有内置的方法来进行upsert(如果不存在则插入)?或者我应该先检查一个项目是否存在,并且只有在那之后才能进行插入/更新?
我在尝试安装CMS时出错.它说Bundler::GemfileNotFound
此外,我跑的bundle时候也说Bundler::GemfileNotFound
我该如何解决?