Tag: C#的

从jQuery调用ASMX

我想从jQuery调用一个ASMX方法没有成功。 以下是我的代码,我不明白我缺less什么。 文件Something.js, function setQuestion() { $.ajax({ type: "POST", data: "{}", dataType: "json", url: "http: //localhost/BoATransformation/Survey.asmx/GetSurvey", contentType: "application/json; charset=utf-8", success: onSuccess }); } function onSuccess(msg) { $("#questionCxt").append(msg); } 文件SomethingElse.cs, [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class Survey : System.Web.Services.WebService { public Survey () { } [WebMethod] [ScriptMethod(UseHttpGet = true)] public string GetSurvey() { […]

我怎样才能撰写输出stream,所以输出一次会有多个地方?

我想编写两个(或更多)stream成一个。 我的目标是任何针对cout , cerr和clog输出都会与原始stream一起输出到文件中。 (例如,当事情被logging到控制台,例如closures后,我想仍然能够返回并查看输出。) 我正在考虑做这样的事情: class stream_compose : public streambuf, private boost::noncopyable { public: // take two streams, save them in stream_holder, // this set their buffers to `this`. stream_compose; // implement the streambuf interface, routing to both // … private: // saves the streambuf of an ios class, // upon destruction restores it, […]

使用用户名和密码连接到networking驱动器

如何提供证书,以便我可以连接到NET中的networking驱动器? 我试图从networking驱动器检索文件,并需要提供用户凭据来访问驱动器。

静态与非静态类成员

一般来说,我都是新手。 我有一个简短的问题 – 关于静态/非静态variables的最佳做法是什么? 我有一个variables,私人int x,属于类y。 要访问这个variables,我需要引用y。 如果x是静态的,但是我可以访问这个variables而不会引用y。 在y类中的几个方法将引用这个值的情况下,哪个是最好的方法? 希望这是有道理的,我的问题不是太基本! 非常感谢

如何获得windows上每个线程的CPU使用率(win32)

寻找Win32 API函数,C ++或Delphi示例代码,告诉我一个线程的CPU使用率(百分比和/或总CPU时间)(而不是一个进程的总数)。 我有线程ID。 我知道,Sysinternals进程资源pipe理器可以显示这些信息,但我需要在我的程序中的这些信息。

函数模板中的魔法参数

在下面的代码中 #include<iostream> template<typename T,size_t N> void cal_size(T (&a)[N]) { std::cout<<"size of array is: "<<N<<std::endl; } int main() { int a[]={1,2,3,4,5,6}; int b[]={1}; cal_size(a); cal_size(b); } 正如所料,两个数组的大小都被打印出来。 但是N如何自动初始化为正确的数组大小(数组是通过引用传递的)? 上面的代码是如何工作的?

无法从List <DerivedClass>转换为List <BaseClass>

我想传递一个DerivedClass的列表到一个函数,该函数需要一个BaseClass的列表,但我得到的错误: cannot convert from 'System.Collections.Generic.List<ConsoleApplication1.DerivedClass>' to 'System.Collections.Generic.List<ConsoleApplication1.BaseClass>' 现在我可以将我的List<DerivedClass>转换为List<BaseClass> ,但我不觉得这样做,除非我明白为什么编译器不允许这样做。 我发现的解释只是简单地说它以某种方式违反了types安全,但是我没有看到它。 谁能帮我吗? 编译器允许从List<DerivedClass>转换为List<BaseClass>的风险是什么? 这是我的SSCCE: class Program { public static void Main() { BaseClass bc = new DerivedClass(); // works fine List<BaseClass> bcl = new List<DerivedClass>(); // this line has an error doSomething(new List<DerivedClass>()); // this line has an error } public void doSomething(List<BaseClass> bc) { // […]

匿名types – 是否有任何distingushing特性?

有没有什么可以用来确定一个types是否实际上是一个匿名types? 例如一个接口等? 目标是创build如下的东西… //defined like… public static T Get<T>(this IAnonymous obj, string prop) { return (T)obj.GetType().GetProperty(prop).GetValue(obj, null); } //… //And then used like… var something = new { name = "John", age = 25 }; int age = something.Get<int>("age"); 还是仅仅是一个匿名types的美丽? 没有什么可以识别自己,因为它需要一个新的形状? 注意 – 我意识到你可以为对象类写一个扩展方法,但在我看来,这似乎有点矫枉过正。

如何在C ++应用程序中访问Java方法

只是一个简单的问题:是否可以从c / c ++调用java函数?

如何实现IComparable接口?

我正在用一个类的实例填充一个数组: BankAccount[] a; . . . a = new BankAccount[] { new BankAccount("George Smith", 500m), new BankAccount("Sid Zimmerman", 300m) }; 一旦我填充这个数组,我想以平衡量对它进行sorting。 为了做到这一点,我希望能够检查每个元素是否可以使用IComparablesorting。 我需要使用接口来做到这一点。 到目前为止,我有以下代码: public interface IComparable { decimal CompareTo(BankAccount obj); } 但我不确定这是否是正确的解决scheme。 任何build议?