runtime

Generate Generic Type At Runtime

♀尐吖头ヾ 提交于 2019-12-11 00:32:39
问题 I am wondering if it is possible to use the type of one variable to set as the type of another generic variable? For example, say I have this code: public class Foo: IBar<ushort> { public FooBar() { Value = 0; } public ushort Value { get; private set; } } I also have this class: public class FooDTO<TType> : IBar<TType> { public TType Value { get; private set; } } In these examples, in the interface for IBar has the property TType Value; Then in my code I have this var myFoo = new Foo(); var

Loading the same Assembly twice but with different version

。_饼干妹妹 提交于 2019-12-11 00:13:49
问题 I have one assembly that is called asm.dll. This assembly has the version 1.0.0.0 ( set within AssemblyInfo.cs ) Then I need do do some code modifications in that assembly (still asm.dll), advance the version to 2.0.0.0 and build it again. Now, I have two files named asm.dll that differ with respect to some code modifications and a their version number. How do I load these two files during runtime? ADDENDUM: Right now I am trying the following: var asm1 = Assembly.LoadFrom("dir1\asm.dll");

Insert custom TypeConverter on a property at runtime, from inside a custom UITypeEditor

≯℡__Kan透↙ 提交于 2019-12-10 22:18:25
问题 I've created a custom UITypeEditor. Can I possibly insert an attribute that also attaches a TypeConverter to my property from inside the UITypeEditor class? I've tried the following, but nothing happens, no matter how I twist and turn it: Attribute[] newAttributes = new Attribute[1]; newAttributes[0] = new TypeConverterAttribute(typeof(BooleanConverter)); Now, the above needs to have the following attached to it somehow: TypeDescriptor.AddAttributes(context.Instance.PROPERTYNAME,

Memory: how does the compiler choose where to store variables? [duplicate]

可紊 提交于 2019-12-10 22:03:56
问题 This question already has answers here : Can a local variable's memory be accessed outside its scope? (20 answers) Closed 5 years ago . Given two functions, func1 and f2, with the following signatures: void func1(){ int baba = 12345; // printf the value of baba here } void f2(){ int loo; //printf the value of loo here } ...if I run my int main, which only has func1 then f2: int main(){ func1(); f2(); } ...then the printed value of both baba and loo will be 12345. So my question is as follows:

Trying to add Tomcat v7 to eclipse, but cannot find it in “Define a New Server” window

女生的网名这么多〃 提交于 2019-12-10 21:07:47
问题 I'm trying to create a dynamic web project in eclipse, but my version of Apache Tomcat is v7 and the list of abvailable tomcat servers when I try to define the new server are from v3.2 to v6.0, there is nothing higher. I tried to click "Download additional server adapters" but could not find any updated versions of tomcat there. I have a tomcat server working on my machine, but I wanted to link it with Eclipse to make development easier. I've also tried going to Window -> Preferences ->

vb.net deleting lots of dynamically created buttons

别等时光非礼了梦想. 提交于 2019-12-10 20:48:51
问题 I'm a new programmer to vb.net, so apologise for what is likely to be ignorance. I’m building a simple gui for a database interface, with many parent and child items within it. Upon a form I create buttons depending on how many items (parents/children). I've got the creation of the buttons thus: For RowNumber As Integer = 0 To NoOfRows Dim Buttoni As New Button Buttoni.Location = New Point(LocationX, LocationY) Buttoni.Width = 100 Buttoni.Height = 40 Buttoni.Visible = True Buttoni.Text =

Time Complexity of Nested For Loop with If

旧街凉风 提交于 2019-12-10 20:05:08
问题 void f(int n) { for(int i =1; i<=n; i++){ if(i % (int)sqrt(n)==0){ for(int k=0; k< pow(i,3); k++){ //do something } } } } My thinking process: number of times execute if statement: sum i=1 to n (theta(1)). number of times execute things inside if: sum i=1 to sqrt(n) (for loop) number of times execute for loops: sum k=0 to i^3 (theta(1)) = i^3 This will give me: theta(n) + sum i=0 to sqrt(n) (theta(i^3)) = theta(n) + theta(n^2) which gives me theta(n^2) The answer key he gave is theta(n^3.5) I

Is it possible to load an assembly targeting a different .NET runtime version in a new app domain?

六月ゝ 毕业季﹏ 提交于 2019-12-10 19:34:27
问题 I've an application that is based on .NET 2 runtime. I want to add a little bit of support for .NET 4 but don't want to (in the short term), convert the whole application (which is very large) to target .NET 4. I tried the 'obvious' approach of creating an application .config file, having this: <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0" /> </startup> but I ran into some problems that I noted here. I got the idea of creating a separate app domain. To

exponential multiplication algorithm that runs in O(n) time?

末鹿安然 提交于 2019-12-10 19:15:42
问题 I am reading an algorithms textbook and I am stumped by this question: Suppose we want to compute the value x^y, where x and y are positive integers with m and n bits, respectively. One way to solve the problem is to perform y - 1 multiplications by x. Can you give a more efficient algorithm that uses only O(n) multiplication steps? Would this be a divide and conquer algorithm? y-1 multiplications by x would run in theta(n) right? .. I don't know where to start with this question 回答1: Apply a

What is the run time of String.toCharArray()?

六眼飞鱼酱① 提交于 2019-12-10 18:35:27
问题 What's the run time of String.toCharArray() in java? The source code is public char[] toCharArray() { // Cannot use Arrays.copyOf because of class initialization order issues char result[] = new char[value.length]; System.arraycopy(value, 0, result, 0, value.length); return result; } Does System.arrayCopy ? have run time of O(n)? The source code doesn't really say much about how it's implemented. Does it go through every element and copies it? Thanks. 回答1: System.arraycopy() is typically an