这听起来像是一个愚蠢的问题,因为如果您使用Google "OOPS"还是"OOPS in C#"会获得大量结果。但。
我知道的概念OOP一样abstraction,inheritance并没有什么......但我想看到的是一些“ 实际可用例如编程”吧。就像polymorphism 您知道的一个实际例子一样Object.GetType。
有时候(如果不是很多的话),我发现自己在做一些事情,例如单击按钮,打开连接并做一些事情,这不是OOP我所知道的,我应该有一个特定的实体/类,并且应该有一个用于我在单击按钮时所做的事情,然后应该调用该方法,而不是在单击按钮时执行所有操作。
另一个例子是,我发现自己在某个the txtEmployeeName.Leave事件中加载了员工从事的所有项目,然后为这些项目填充了组合。这也不是面向OOP的,我应该具有class Employee和一个方法,该方法可以加载该员工从事的所有项目,然后在处调用该方法txtEmployeeName.Leave。
当我发现或阅读某个地方(在线或其他地方)时,我看到类似的东西是,Vehicle是一个抽象类,并且Car是一个Vehicle,因此它是从继承的Vehicle,这是Inheritance。我们都知道,但这不是实际的事情。我发现的另一个示例是,如果我们有一个方法MakeSound,并且将其称为对象Cat,它将成为对象Purr,但是如果我们对调用相同的方法Dog,它将Bark是Polymorphism。
它对理解很有帮助,但不是“ 实用 ”的,或者您应该说“ 真实的编程示例 ”。因此,我需要知道的是,有什么好的资源(在线,书籍或其他资源),我可以阅读有关OOP的内容,但不像我在上一段中所给出的实例一样,但是实际上有一些“真实的编程示例”使我的代码更OO?
祝大家美好的一天 这是我在这里的第一篇文章.我正在阅读"使用MFC编程Windows - J Prosise(MS Press)"
在第二章中,我遇到了2个GDI函数,这些函数让我很困惑,我引用了文本:
很容易让SetViewportOrg和SetWindowOrg混淆,但它们之间的区别实际上非常清楚.使用SetViewportOrg将视口原点更改为(x,y)告诉Windows将逻辑点(0,0)映射到设备点(x,y).使用SetWindowOrg将窗口原点更改为(x,y)基本上相反,告诉Windows将逻辑点(x,y)映射到设备点(0,0) - 显示表面的左上角.在MM_TEXT映射模式中,两个函数之间唯一真正的区别是x和y的符号.在其他映射模式中,除此之外还有更多因为SetViewportOrg处理设备坐标和SetWindowOrg处理逻辑坐标
我真的很困惑,就像我们将视点原点改为说(50,50)然后使用dc.ellipse(0,0,50,50)它将从设备点(50,50)开始原点,但如果我们将窗口原点更改为(50,50),这意味着现在逻辑点(50,50)将被映射到(0,0),如果这样,则椭圆不会在客户区域之外上部地区?什么映射模式是MM_LOWENGLISH或其他什么?情况怎么会改变呢?如果有人能对这件事有所了解,我真的很感激
这段代码为名为的事件添加了新的EventHandler寄存器NewMail(eventargs类被命名NewMailEventArgs.
// A PUBLIC add_xxx method (xxx is the event name)
// Allows methods to register interest in the event.
public void add_NewMail(EventHandler<NewMailEventArgs> value) {
// The loop and the call to CompareExchange is all just a fancy way
// of adding a delegate to the event in a thread-safe way.
EventHandler<NewMailEventArgs> prevHandler;
EventHandler<NewMailEventArgs> newMail = this.NewMail;
do {
prevHandler = newMail;
EventHandler<NewMailEventArgs> newHandler = (EventHandler<NewMailEventArgs>)Delegate.Combine(prevHandler, value);
newMail = Interlocked.CompareExchange<EventHandler<NewMailEventArgs>>(ref this.NewMail, newHandler, prevHandler);
}
while(newMail != …Run Code Online (Sandbox Code Playgroud) 我有这个dropdown,我想在其中的值被更改时提醒/记录某事.当我单击dropdown鼠标并选择任何其他值时,会发生更改事件.但是,当焦点在dropdown,我按up和down箭头,它改变下拉列表中值,但不会触发事件,并提醒正在显示出来.这是代码
<select id="drpDay" name="drpDay" style="background-color: white;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7" selected="selected">7</option>
</select>
</br>
<select id="drpMonth" name="drpMonth" style="background-color: white;">
<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option value="Mar">Mar</option>
<option value="Apr">Apr</option>
<option value="May">May</option>
<option value="Jun">Jun</option>
<option value="Jul">Jul</option>
<option value="Aug">Aug</option>
<option value="Sep">Sep</option>
<option value="Oct">Oct</option>
<option value="Nov" selected="selected">Nov</option>
<option value="Dec">Dec</option>
</select>
</br>
<label id="lbl" text="" width="auto">adsf</label>
Run Code Online (Sandbox Code Playgroud)
js是
$('#drpDay, #drpMonth').change(function(event) {
alert(event.which);
$('#lbl').text('change ' + event.which + ' …Run Code Online (Sandbox Code Playgroud) 我想要的是,有一个最大长度为5的文本框.允许的值是..
我找到了这个页面,http://www.regular-expressions.info/refadv.html
所以我的想法就是这样
所以,我制作的正则表达式是......
a single digit one or more => /d+
an optional decimal point followed by exactly one digit => (?:[.]\d{1})?
if first condition matches => (?(first condition) => (?((?<=\d+)
then, match the option decimal and one exact digit =>(?((?<=\d+)(?:[.]\d{1})?
else => |
find if there is a decimal and one exact digit => (?:[.]\d{1}){1}
check the whole condition globally => /gm
Run Code Online (Sandbox Code Playgroud)
整体表达=>
(?(?<=\d+)(?:[.]\d{1}){1}|(?:[.]\d{1}){1})+/gm
Run Code Online (Sandbox Code Playgroud)
但它没有输出任何东西..
这是小提琴
ps:那里的pattern1和pattern2与我之前的问题有关.
我正在运行一些测试,看看我的日志记录将如何执行而不是File.AppendAllText我先写入内存流然后复制到文件.所以,只是为了看看内存操作有多快我就这样做了..
private void button1_Click(object sender, EventArgs e)
{
using (var memFile = new System.IO.MemoryStream())
{
using (var bw = new System.IO.BinaryWriter(memFile))
{
for (int i = 0; i < Int32.MaxValue; i++)
{
bw.Write(i.ToString() + Environment.NewLine);
}
bw.Flush();
}
memFile.CopyTo(new System.IO.FileStream(System.IO.Path.Combine("C", "memWriteWithBinaryTest.log"), System.IO.FileMode.OpenOrCreate));
}
}
Run Code Online (Sandbox Code Playgroud)
当i达到25413324我得到了Exception of type 'System.OutOfMemoryException' was thrown.,即使我的Process Explorer的说,我对自由的RAM 700MB ???
这是屏幕截图(以防万一)
Process Explorer

这是winform

编辑:为了在堆上创建更多对象,我重写了bw.write这个
bw.Write(i);
Run Code Online (Sandbox Code Playgroud) 我正在阅读C# 5.0 in nutshell并在阅读了作者的观点后,我对我应该采用什么感到困惑.我的要求是说我有一个很长时间运行(计算量很大)的任务,例如,计算数百万个文件的SHA1(或其他一些)哈希值,或者实际上任何其他东西都是计算量很大并且可能需要一些时间什么应该是我对发展它的方法(winforms如果该事项,使用VS 2012,C#5.0) so that I can also report progress to the user.
以下情景浮现在脑海中......
创建一个Task(与LongRunning该计算哈希值,并报告进度,用户选择或者通过实施IProgess<T>或Progess<T> 或让任务捕捉SynchronizationContext上下文和张贴到UI.
创建一个Async类似的方法
async CalculateHashesAsync()
{
// await here for tasks the calculate the hash
await Task.Rung(() => CalculateHash();
// how do I report progress???
}
Run Code Online (Sandbox Code Playgroud)使用TPL(或PLINQ)作为
void CalcuateHashes()
{
Parallel.For(0, allFiles.Count, file => calcHash(file)
// how do I report progress …Run Code Online (Sandbox Code Playgroud)c# multithreading task-parallel-library async-await visual-studio-2012
据我所知,try和finally块是用来执行一段代码可能抛出一些exception,我们还加catch块,如果我们准备处理一些异常类型和/或在它们以外,像FileIOException,AccessRight或什么的.但是当我跑这个..
private void button1_Click(object sender, EventArgs e)
{
try
{
Environment.FailFast("It failed");
}
finally
{
MessageBox.Show("Done");
}
}
Run Code Online (Sandbox Code Playgroud)
它打破了一个例外并说
检测到FatalExecutionEngineError
消息:运行时遇到致命错误.错误的地址位于线程0xd04处的0x032526f4处.错误代码是0x80131623.此错误可能是CLR中的错误,也可能是用户代码的不安全或不可验证部分中的错误.此错误的常见来源包括COM-interop或PInvoke的用户编组错误,这可能会破坏堆栈.
现在msdn说
通常,当未处理的异常结束应用程序时,无论finally块是否运行都不重要.但是,如果在finally块中有语句,即使在这种情况下也必须运行,一种解决方案是在try-finally语句中添加一个catch块.
所以,我添加了catch块,但它仍然说同样的事情.
private void button1_Click(object sender, EventArgs e)
{
try
{
Environment.FailFast("It failed");
}
catch (Exception ex)
{
}
finally
{
MessageBox.Show("Done");
}
}
Run Code Online (Sandbox Code Playgroud)
它再次失败并出现同样的错误.至于CLR说最终总是运行代码块(至少在添加catch时),情况肯定不是这样.评论/意见谁?
还有这里的快照..

我是新手Haskell,我正在阅读" 了解你一个Haskell",并在页面中宣布了一个函数
tell :: (Show a) => [a] -> String
tell [] = "The list is empty"
tell (x:[]) = "The list has one element: " ++ show x
tell (x:y:[]) = "The list has two elements: " ++ show x ++ " and " ++ show y
tell (x:y:_) = "This list is long. The first two elements are: " ++ show x ++ " and " ++ show y
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.这本书说
这个函数是安全的,因为它处理空列表,单例列表,包含两个元素的列表和包含两个以上元素的列表.注意,(x:[])和(x:y:[])可以重写为[x]和[x,y](因为它的合成糖,我们不需要括号).我们不能用方括号重写(x:y:_),因为它匹配任何长度为2或更长的列表.
我尝试通过将最后一行改为来做到这一点
-- same as …Run Code Online (Sandbox Code Playgroud) 我有这门课
public class Parent
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public virtual Child Child { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和一个儿童班
public class Child
{
[Key]
[ForeignKey]
public int ParentId { get; set; }
public string Name { get; set; }
public virtual Parent Parent { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这种关系使父母可以有0或1个孩子.我检查了SO并找到了两个解决方案.
modelBuilder.Configurations.Add(new ParentChildMap());
// solution 1
class ParentChildMap : EntityTypeConfiguration<Child>
{
public ParentChildMap()
{
HasRequired(t => t.Parent).
WithRequiredDependent(t => t.Child);
} …Run Code Online (Sandbox Code Playgroud)