我有这样的代码......
class Time
{
public:
Time(int, int, int);
void set_hours(int);
void set_minutes(int);
void set_seconds(int);
int get_hours() const;
int get_minutes() const;
int get_seconds() const;
static void fun() ;
void printu() const;
void prints();
private:
int x;
int hours;
int minutes;
int seconds;
const int i;
};
Run Code Online (Sandbox Code Playgroud)
为什么我需要const最后才能使函数成为常量类型,但如果我需要创建一个函数,我可以这样做......
static void Time::fun()
{
cout<<"hello";
}
Run Code Online (Sandbox Code Playgroud)
以上功能fun()也属于同一类.我只是想知道这背后的原因是什么?
如果我想保存this为jQuery DOM对象,然后选择它,我应该使用下面的方法?
var element = $(this)
Run Code Online (Sandbox Code Playgroud)
然后选择
$(element)
Run Code Online (Sandbox Code Playgroud)
或者干脆
var element = this
Run Code Online (Sandbox Code Playgroud)
此外,如果我想要连接element到更大的选择器,是这样的:
$(element + " .class")
Run Code Online (Sandbox Code Playgroud)
正确的方式?
我有一个WebForms应用程序,其中第一页基本上是一个网格,其中包含指向第二页的链接,该第二页加载PDF查看器.网格实际上位于.ascx控件中.从第一页到PDF查看器页面,一切正常.但是,当我按下后退按钮返回第一页时.我收到以下错误(在Chrome中,但这也发生在其他浏览器中):

如果我单击后退按钮然后浏览器返回到第一页,一切都很好,但我需要解决此错误.
我已经尝试根据StackOverflow答案的建议在第一页中禁用缓存,如下所示:
Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
Response.Cache.SetExpires(DateTime.MinValue);
Run Code Online (Sandbox Code Playgroud)
我已将此代码放在.aspx页面和.ascx控件(在OnInit方法中)后面的代码中,但都无济于事.我在这里错过了什么?
我正在学习CLR中的托管和非托管代码.所以我用C#中的C风格指针编写了这个例子:
unsafe static void Main(string[] args)
{
int x;
int* y;
y = &x;
*y = 50;
Console.WriteLine(*y);
Console.WriteLine(((int)y).ToString());
}
Run Code Online (Sandbox Code Playgroud)
所以我想知道我从上面的代码得到的IL代码中真正不安全的是什么?
.assembly extern mscorlib
{}
.assembly UnsafePointers
{}
.module UnsafePointers.exe
.class private auto ansi beforefieldinit UnsafePointers.Program
extends [mscorlib]System.Object
{
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 34 (0x22)
.locals init (int32 x,
int32* y)
IL_0001: ldloca x
IL_0003: conv.u
IL_0004: stloc y
IL_0005: ldloc y
IL_0006: ldc.i4 50
IL_0008: stind.i4
IL_0009: ldloc y …Run Code Online (Sandbox Code Playgroud) 这是设置:我已经创建了一个用户控件MyUserControl.在此控件上是一个简单的标签.当我在表单上删除此控件的新实例时,我希望标签是控件的名称.例如,如果这是控件的第一个实例,VStudio会自动将其名称设置为"myUserControl1".我只想把标签读作"myUserControl1".如果这是第五个控件,VStudio会将其命名为myUserControl5.我希望标签能够相应改变......但仅限于尚未设置的标签.一旦我将其设置为"标签",它应该保持不变.
我觉得这很容易.在构造函数中,设置label1.Text = this.Name.但后来我意识到,在实例化时,这个名字只是MyUserControl.它还没有被VisualStudio和CONTAINING InitializeComponent()方法命名.
啊! 我只是覆盖"名称"字段.设置完成后,检查DesignMode并更新标签!...但我无法覆盖名称.它不是虚拟的或抽象的.我可以使用"新"强制它,但是,它永远不会发射,从而击败目的.
我可以用哪个事件来表示设计师何时命名控件?我知道当他们放弃对窗体的控制时,redmond人会一直这样做,所以这很有可能.我实际上对这个小谜语感到很难过.
我有这个功能:
static void Func1<T>(T x, T y)
{
dynamic result = ((dynamic)x + y); //line 1
dynamic result2 = (x + y); //line 2
}
Run Code Online (Sandbox Code Playgroud)
这个func可以执行为Func(1,2);但是,第1行是OK,而第2行是BANG(在编译时).
从第2行抛出的异常是:
运算符'+'不能应用于'T'和'T'类型的操作数
因此,我们需要创建一个运算符重载.好的,到目前为止一切顺利.
但是第1行呢?它不应该也需要动态演员y吗?
((dynamic)x + (dynamic)y);
我知道它正在运行时进行评估,但为什么C#编译器接受第+1行中的运算符(即错误地认为T可以是+其他东西)?
我有一个委托与泛型类型作为参数之一:
public delegate void UpdatedPropertyDelegate<T>(
RemoteClient callingClient,
ReplicableProperty<T> updatedProp,
ReplicableObject relevantObject
);
Run Code Online (Sandbox Code Playgroud)
现在,我想要一个可以订阅的公共事件供其他类使用.因此,我做了:
public event UpdatedPropertyDelegate<T> UpdatedProperty;
Run Code Online (Sandbox Code Playgroud)
但是,编译器不喜欢这样.我不明白为什么必须在这里指定T. 当然,它是在我发射事件时指定的,即:
if (UpdatedProperty != null)
{
UpdatedProperty(this, readProperty,
ReplicableObjectBin.GetObjectByID(readProperty.OwnerID));
}
Run Code Online (Sandbox Code Playgroud)
那么,我做了一些简单的错误吗?或者这是一次大规模的理解失败?
谢谢.
是否可以使用jquery .on()方法而不是.delegate()没有要监听的事件?
根据.on()文件:
.on(events [,selector] [,data],handler(eventObject))
该events参数是不可选的.
使用.on()/ .delegate()是动态添加元素.
如何格式化以下行以消除StyleCop警告:
this.BeginInvoke(this.updateHandler,new object[]{this.tmpbuf});
Run Code Online (Sandbox Code Playgroud)
现在,我得到4个警告:
Warning 4 SA1001: Invalid spacing around the comma.Warning 5 SA1011: Invalid spacing around the closing square bracket.Warning 6 SA1012: Invalid spacing around the opening curly bracket.Warning 7 SA1013: Invalid spacing around the closing curly bracket.假设您正在调试.有一次你在方法A中,它有一个类型的参数foo Foo.稍后你在方法B,它也采用类型的参数foo Foo.
这两个变量可能是同一个Foo实例,但你怎么说呢?因为他们在不同的范围,你不能打电话ReferenceEquals().有没有什么方法可以获得变量指向的实际内存位置,以便您可以判断它们是否是实例?