// Cannot change source code
class Base
{
public virtual void Say()
{
Console.WriteLine("Called from Base.");
}
}
// Cannot change source code
class Derived : Base
{
public override void Say()
{
Console.WriteLine("Called from Derived.");
base.Say();
}
}
class SpecialDerived : Derived
{
public override void Say()
{
Console.WriteLine("Called from Special Derived.");
base.Say();
}
}
class Program
{
static void Main(string[] args)
{
SpecialDerived sd = new SpecialDerived();
sd.Say();
}
}
Run Code Online (Sandbox Code Playgroud)
结果是:
来自Special Derived.
来自Derived./*这不是预期的*/
从Base调用.
如何重写SpecialDerived类,以便不调用中产阶级"Derived"的方法?
更新: 我想继承Derived而不是Base的原因是Derived类包含许多其他实现.既然我不能在 …
我试着运行$ bundle exec rake db:reset并在控制台上找到以下内容
Couldn't drop db/development.sqlite3 : #<Errno::EACCES: Permission denied - c:/sample_app/db/development.sqlite3>
db/development.sqlite3 already exists
-- create_table("users", {:force=>true})
-> 0.3940s
-- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})
-> 0.1280s
-- initialize_schema_migrations_table()
-> 0.0010s
-- assume_migrated_upto_version(20120419034627, ["c:/sample_app/db/migrate
"])
-> 0.0040s
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
编辑我正在关注一个教程,它告诉我运行上面的命令来安全地删除数据库中的所有数据.我也在使用管理员帐户.
我做了一个批处理文件试图在Windows上设置rake/albacore环境:
@echo off
echo Setting up rake environment for building
echo Installing Bundler
gem install bundler
echo Bundle Installing gems
bundle install
Run Code Online (Sandbox Code Playgroud)
当我运行此批处理文件(双击或在cmd窗口内运行)时,只执行第一个gem命令.永远不会调用'bundle install'.这是输出:
C:\>InstallGems.bat
Setting up rake environment for building
Installing Bundler
Successfully installed bundler-1.2.1
1 gem installed
Installing ri documentation for bundler-1.2.1...
Installing RDoc documentation for bundler-1.2.1...
C:\>
Run Code Online (Sandbox Code Playgroud)
我在第一个'gem install'命令之后添加了'pause',似乎'暂停'也从未执行过.
任何的想法?
在使用C#4.0/C#2.0的WinForms中,如果控件的可见字段为false,则无法绑定到控件:
this.checkBox_WorkDone.DataBindings.Add("Visible", WorkStatus, "Done");
Run Code Online (Sandbox Code Playgroud)
我可以确认绑定已成功添加到控件的数据绑定列表中,但如果我更改绑定对象(WorkStatus),则不会发生任何事情.
这就是WorkStatus的样子:
public class WorkStatus : INotifyPropertyChanged
{
private Boolean _done;
public Boolean Done
{
get { return _done; }
set
{
if (_done == value) return;
_done = value;
// fire event
RaisePropertyChanged("Done");
}
}
private Int32 _time;
public Int32 Time
{
get { return _time; }
set
{
if (_time == value) return;
_time = value;
// fire event
RaisePropertyChanged("Time");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(String propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
} …Run Code Online (Sandbox Code Playgroud) 这对我来说真的是一个奇怪的错误,我花了很长时间才弄清楚发生了什么.为了简化和重现,只需使用VS2005创建一个空的win32控制台应用程序,并在main方法中使用此代码:
float a = 411.00418f;
float b = 1.0f;
float c = 0.076279849f;
unsigned short result = (unsigned short)( (a-b)/c );
unsigned short result2 = (unsigned short)( (float)((a-b)/c) );
// Debug: 5374, 5375
// Release: 5374, 5374
printf("%d, %d\n", result, result2);
Run Code Online (Sandbox Code Playgroud)
为什么result2在调试/释放模式下显示不同的值?
这是以下观点jade:
button#save-csv-btn(ng-click="click()") Export CSV
input#save-csv(style="display:none", type="file", onchange="angular.element(this).scope().saveCSVFileChanged(this)")
Run Code Online (Sandbox Code Playgroud)
JS:
$scope.click = ->
# $('#save-csv').trigger('click')
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
Error: $apply already in progress
Run Code Online (Sandbox Code Playgroud) 我有一个方法 Foo() 做了一些艰苦的工作,在 UI 层我有一个按钮来调用该方法。
我想要做的就是调用该方法并在 Foo() 方法出现问题时显示一个消息框。
我有两种选择来设计方法签名:
1.元组
Tuple<bool, string> Foo()
{
if(!DoHardWorkA()) return Tuple.New(false, "cannot do hardwork A");
if(!DoHardWorkB()) return Tuple.New(false, "cannot do hardwork B");
return Tuple.New(true, String.Empty);
}
Run Code Online (Sandbox Code Playgroud)
2.异常
void Foo()
{
if(!DoHardWorkA()) throw new ProgramSpecificException("cannot do hardwork A");
if(!DoHardWorkB()) throw new ProgramSpecificException("cannot do hardwork B");
return Tuple.New(true, String.Empty);
}
Run Code Online (Sandbox Code Playgroud)
DoHardWorkA() 和 DoHardWorkB() 都是我无法控制的外部方法,它们返回 true/false 指示结果。
从逻辑上讲,我认为我应该选择选项 2,因为它们确实是例外;但为了一致性,我想选择选项 1。
你更喜欢哪一个,为什么?
我有一个C++程序,它有一些插件结构:当程序启动时,它在插件文件夹中查找带有某些导出函数签名的dll,例如:
void InitPlugin(FuncTable* funcTable);
Run Code Online (Sandbox Code Playgroud)
然后程序将调用dll中的函数来初始化并将函数指针传递给dll.从那时起,dll可以与程序通信.
我知道Cython允许你在Python中调用C函数,但我不确定我是否可以编写一个Cython代码并将其编译为dll,这样我的C++程序就可以用它进行初始化.一个示例代码会很棒.
我有一个动态List of Point,可以随时添加新Point.我想绘制线条以使用不同的颜色连接它们.颜色基于这些点的索引.这是代码:
private List<Point> _points;
private static Pen pen1 = new Pen(Color.Red, 10);
private static Pen pen2 = new Pen(Color.Yellow, 10);
private static Pen pen3 = new Pen(Color.Blue, 10);
private static Pen pen4 = new Pen(Color.Green, 10);
private void Init()
{
// use fixed 80 for simpicity
_points = new List<Point>(80);
for (int i = 0; i < 80; i++)
{
_points.Add(new Point(30 + i * 10, 30));
}
}
private void DrawLinesNormal(PaintEventArgs e)
{
for (int i = …Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×2
c++ ×2
angularjs ×1
batch-file ×1
c ×1
cython ×1
data-binding ×1
dll ×1
exception ×1
gdi+ ×1
gem ×1
math ×1
plugins ×1
polymorphism ×1
python ×1
return-value ×1
ruby ×1
sqlite ×1
visual-c++ ×1
winforms ×1