我正在阅读Accelerated C#2010.并且有一些问题
问题1
String的实例是不可变的,因为一旦你创建它们,你就无法改变它们
怎么回事呢.我有一段时间没有使用过C#,而且我刚刚开始,所以即使在语法中我也许错了.
string str1 = "this is a string"; // i hope my syntax is right
str1 = "this is a NEW string"; // i think i can do this right?
Run Code Online (Sandbox Code Playgroud)
问题2
如果在字符串上调用ICloneable.Clone方法,则会得到一个指向与源相同的字符串数据的实例.事实上,ICloneable.Clone只是返回对此的引用
如果这是真的,那就意味着
string str1 = "string 1";
// i hope my syntax is right too. i am really not sure about this
string str2 = str1.Clone();
str2 = "modified string"; // will str1 be modified too?
Run Code Online (Sandbox Code Playgroud) 我正在使用MVVM Foundation的SampleModel项目.Wwh ICommand在_decrementCommand声明为时返回RelayCommand.我知道RelayCommand继承ICommand但不会更清楚只返回一个RelayCommand?
public ICommand DecrementCommand {
get { return _decrementCommand ?? (_decrementCommand = new RelayCommand(() => --this.Value)); }
}
RelayCommand _decrementCommand;
Run Code Online (Sandbox Code Playgroud) 可能重复:
为什么每次触发事件时C#都要求您写一个空检查?
我经常看到以下代码,但不知何故得不到它.
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("UIState"));
Run Code Online (Sandbox Code Playgroud)
为什么我需要在搜索之前检查事件是否为null.所有的时间,至少在我尝试的时候,我可以通过举起活动来逃避.
我只是想知道这是在MVVM中显示对话框的方式吗?
public ICommand OpenFileCommand
{
get
{
if (_openFileCommand == null) {
_openFileCommand = new RelayCommand(delegate
{
var strArr = DialogsViewModel.GetOpenFileDialog("Open a file ...", "Text files|*.txt | All Files|*.*");
foreach (string s in strArr) {
// do something with file
}
});
}
return _openFileCommand;
}
}
public class DialogsViewModel {
public static string[] GetOpenFileDialog(string title, string filter)
{
var dialog = new OpenFileDialog();
dialog.Title = title;
dialog.Filter = filter;
dialog.CheckFileExists = true;
dialog.CheckPathExists = true;
dialog.Multiselect = true;
if …Run Code Online (Sandbox Code Playgroud) 我对逐渐将文件读入缓冲区的步骤感到困惑.
来自MSDN文档
public abstract int Read(
byte[] buffer,
int offset,
int count
)
Run Code Online (Sandbox Code Playgroud)
源自C#的例子
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
{
int length = (int)fileStream.Length; // get file length
buffer = new byte[length]; // create buffer
int count; // actual number of bytes read
int sum = 0; // total number of bytes read
// read until Read method returns 0 (end of the stream has been reached)
while ((count = fileStream.Read(buffer, sum, length - sum)) > …Run Code Online (Sandbox Code Playgroud) 我收到了这个错误
Fatal error: Call to a member function hasResource() on a non-object in D:\Projects\Tickle\application\controllers\ErrorController.php on line 53
第53行看起来像
if (!$bootstrap->hasResource('Log')) {
Run Code Online (Sandbox Code Playgroud)
这似乎是$this->getInvokeArg('bootstrap')回归null.我没有其他错误.我在其他地方读到另一个问题,可能会引发异常,重置我的控制器或引导程序或类似的东西.是否有可能不显示该例外?甚至在PHP错误日志中?
我当前的设置看起来像
单个测试运行正常,但我仍然遇到错误
D:\Projects\Tickle\tests>phpunit
PHPUnit 3.5.5 by Sebastian Bergmann.
.
Fatal error: Call to a member function hasResource() on a non-object in D:\Projects\Tickle\application\controllers\Error
Controller.php on line 53
Run Code Online (Sandbox Code Playgroud) 我知道并使用了非常基本的Zend Framework的Layouts,我在整个站点中使用了1个布局.但现在我需要一个更中间/有组织的设置.
div#mainContent占用整个12列(使用960gs)div#mainContent占用9列+侧栏,3列我正在考虑使用1个基本布局,其中2个子布局将"扩展".基本布局将只包含<html>声明headScripts等,直到子<body>布局将包含对包装的定义divs div.grid_12, grid_9, grid_3.我怎样才能实现这种"扩展",基本上,我只想重用代码
还有什么是渲染侧边框/小部件的好方法
我想知道View应该传递对象还是应该只接收数组.我正在使用ORM框架.因此,在项目视图页面中,我可以将视图传递给项目对象,并让它呈现项目的todoLists和todos.
所以目前在我看来我的代码如下:
foreach ($this->project->getTodoLists() as $todoList) {
// render lists
foreach ($todoList->getTodos() as $todo) {
// render todos
}
}
Run Code Online (Sandbox Code Playgroud)
这个可以吗?我认为使用doctrine的延迟加载,它会在get*()调用时运行SQL .这有关系吗?
或者我应该在我的控制器中将所有必需的信息解析为纯数组?
我使用PHP,Zend Framework 1.11,Doctrine 2 ORM.但在我看来,我使用的并不重要
使用类表继承,
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
*/
class Person
Run Code Online (Sandbox Code Playgroud)
如何从实体获取类型信息?既然discr是数据库列,而不是实体的属性?
c# ×5
doctrine-orm ×2
mvvm ×2
css ×1
doctrine ×1
filestream ×1
io ×1
php ×1
phpunit ×1
wpf ×1
zend-layout ×1
zend-test ×1
zend-view ×1