我正在学习C#中的事件/代表.我可以问一下你对我所选择的命名/编码风格的看法(取自Head First C#书)吗?
我明天正在和朋友一起教这个问题,并且正在尝试用最优雅的方式来解释这些概念.(认为理解一门学科的最好方法就是尝试教它!)
class Program
{
static void Main()
{
// setup the metronome and make sure the EventHandler delegate is ready
Metronome metronome = new Metronome();
// wires up the metronome_Tick method to the EventHandler delegate
Listener listener = new Listener(metronome);
metronome.OnTick();
}
}
Run Code Online (Sandbox Code Playgroud)
public class Metronome
{
// a delegate
// so every time Tick is called, the runtime calls another method
// in this case Listener.metronome_Tick
public event EventHandler Tick;
public void OnTick()
{
while (true) …Run Code Online (Sandbox Code Playgroud) 在webforms我会做
<script type="text/JavaScript">
function timedRefresh(timeoutPeriod) {
setTimeout("location.reload(true);", timeoutPeriod);
}
</script>
<body onload="JavaScript:timedRefresh(5000);">
Run Code Online (Sandbox Code Playgroud)
或代码隐藏Page_Load
Response.AddHeader("Refresh", "5");
Run Code Online (Sandbox Code Playgroud)
问题 如何在ASP.NET MVC3中每5秒刷新一次屏幕
在我当地的git repo上,我有很多提交,其中包括"秘密"连接字符串:-)
当我把它推到那里时,我不希望这个历史记录在github上.
基本上我想推动我拥有的一切,但想要摆脱大量的历史.
也许我会更好地在我的所有开发人员的分支中运行,然后在提交之前合并回到master ...那么master的历史将只是我想要的提交.
我试过运行rebase:
git rebase –i HEAD~3
返回3次提交,然后我可以删除提交.
然而遇到汽车樱桃挑选失败,它变得相当复杂.
任何想法都非常感激...历史可以没什么大不了的,如果这太难了就重新开始:-)
我第一次尝试MVC.我试图实现一个简单的例子.来自这里的灵感.我有这种模式(还是!)?
查看:"嘿,控制器,用户只是告诉我他想要第一个人"
控制员:"嗯,检查了他的证书,他被允许这样做......嘿,模特,我希望你让我成为第一个人"
型号:"第一个人......得到它.回到你身边,控制器."
控制器:"在这里,我将收集新的数据集.回到你身边,查看."
查看:"很酷,我现在将向用户展示第一个人."
视图:
namespace WinFormMVC
{
public partial class Form1 : Form
{
controller cont = new controller();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = cont.checkPermissionsAndGetFirstPerson();
}
}
}
Run Code Online (Sandbox Code Playgroud)
控制器:
public class controller
{
public string checkPermissionsAndGetFirstPerson()
{
string returnValue = "";
if (checkPermissions())
{
model m = new model();
returnValue = m.getFirstPerson();
}
return returnValue;
}
public bool checkPermissions()
{
return true;
}
} …Run Code Online (Sandbox Code Playgroud) 问题:如何使用键盘快捷键将鼠标悬停在VS2010中的工具提示上?
Ctrl+ Shift+ Space提供了有关重载的一些细节.
干杯
戴夫
public ActionResult About()
{
return View();
}
Run Code Online (Sandbox Code Playgroud) 发送HTML和Text电子邮件是最佳做法吗?
如果我只发送HTML有什么危险?
我正在考虑下面这样的事情
try
{
// Assign a sender, recipient and subject to new mail message
MailAddress sender =
new MailAddress("sender@johnnycoder.com", "Sender");
MailAddress recipient =
new MailAddress("recipient@johnnycoder.com", "Recipient");
MailMessage m = new MailMessage(sender, recipient);
m.Subject = "Test Message";
// Define the plain text alternate view and add to message
string plainTextBody =
"You must use an email client that supports HTML messages";
AlternateView plainTextView =
AlternateView.CreateAlternateViewFromString(
plainTextBody, null, MediaTypeNames.Text.Plain);
m.AlternateViews.Add(plainTextView);
// Define the html alternate view with embedded image …Run Code Online (Sandbox Code Playgroud) 我正在使用VS2008Express在NET3.5SP1中构建一个winForms应用程序.我试图使用System.Web.Script.Serialization库反序列化对象.
错误是:类型'jsonWinForm.Category'不支持反序列化数组.
干杯!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
namespace jsonWinForm {
public class Category
{
public int categoryid;
public string name;
public int serverimageid;
public DateTime dateuploaded;
public bool enabled;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
using (WebClient client = new WebClient())
{
//manipulate request headers (optional) …Run Code Online (Sandbox Code Playgroud) 刚刚从VS2010 Professional转移到Premium.
当我使用MSTEST命中失败的Assert时,它不再在调试器中停止(它确实在测试结果中产生了正确的失败)
问题: 当我运行测试时,如何让调试器在失败的断言上停止

我理解事件在C#中的运作方式(在这个领域是一个公平的新手).我想要了解的是我们使用事件的原因.
您是否知道使用事件的编码良好/架构好的应用程序?
来自http://msdn.microsoft.com/en-us/library/system.math.pow.aspx
int value = 2;
for (int power = 0; power <= 32; power++)
Console.WriteLine("{0}^{1} = {2:N0}",
value, power, (long) Math.Pow(value, power));
Run Code Online (Sandbox Code Playgroud)
Math.Pow将双精度作为参数,但在这里我们传递的是int.
问题:如果隐式转换为双重发生,是否存在浮点舍入错误的危险?
如果是,最好使用以下内容:
public static int IntPow(int x, uint pow)
{
int ret = 1;
while (pow != 0)
{
if ((pow & 1) == 1)
ret *= x;
x *= x;
pow >>= 1;
}
return ret;
}
Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net-mvc ×2
architecture ×1
asp.net ×1
delegates ×1
email ×1
events ×1
git ×1
github ×1
javascript ×1
json ×1
mstest ×1
pow ×1
winforms ×1