How do you apply a .net attribute to a return type
How do I apply the MarshalAsAttribute to the return type of the code below? public ISomething Foo() { return new MyFoo(); } ...
How do I apply the MarshalAsAttribute to the return type of the code below? public ISomething Foo() { return new MyFoo(); } ...
Why don't we see C-like languages that allow for callables with polymorphism in the return type? I could see how the additional type inference would be a hurdle, but we have plenty of languages with full-fledged type inference systems (that work for varying levels of "work"). Edit: By return type polymorphism I mean overloading the func...
I'm having a bit of a problem with converting the result of a MySQL query to a Java class when using SUM. When performing a simple SUM in MySQL SELECT SUM(price) FROM cakes WHERE ingredient = 'chocolate'; with price being an integer, it appears that the SUM sometimes returns a string and sometimes an integer, depending on the version...
I have been assigned a project to develop a set of classes that act as an interface to a storage system. A requirement is that the class support a get method with the following signature: public CustomObject get(String key, Date ifModifiedSince) Basically the method is supposed to return the CustomObject associated with the key if an...
This always forces us to return a single parameter in case I need to return multiple, say a List and a String. This restriction is not there in function arguments. ...
I've been reading Josh Bloch's 'Effective Java 2nd Edition'. Item 43 states 'Return empty arrays or collections, not nulls'. My question is how can I search for all methods in a project that return an implementation of java.util.Collection interface? IDE that is used is Eclipse, but any way of finding the right result is acceptable, e.g....
What's the preferred container type when returning multiple objects of the same type from a function? Is it against good practice to return a simple array (like MyType[]), or should you wrap it in some generic container (like ICollection<MyType>)? Thanks! ...
Is it good to have all the setter functions return a reference to the object in c++? ...
If I am building a string using a StringBuilder object in a method, would it make sense to: Return the StringBuilder object, and let the calling code call ToString()? return sb; OR Return the string by calling ToString() myself. return sb.ToString(); I guess it make a difference if we're returning small, or large strings. What wo...
When I try to use my iterator class template<class T> class list { public: class iterator; }; template<class T> class list<T>::iterator { //stuff }; as a return type in an operator overloading, template<class T> class list<T>::iterator { public: iterator& operator++(); protected: list* lstptr; }; template<class T> iterator& list<T>...
String[] decode(String message) Above is an example. I need to get 2 strings s1 and s2 as the return values for the decode function. How should I proceed? ...
This is for Excel and VBA. Assume that BondClass has been properly defined in a Class Module. I get a #VALUE! when I type "=GetBondPrincipal()" into an Excel cell. Have I done something syntactically wrong or is this just not possible in Excel/VBA? I ask because what I really want to do is this: http://stackoverflow.com/questions/1354046...
I am having a problem with the return type of a method. The method returns a linq object which at present returns type tblAppointment. This method is shown below: public tblAppointment GetAppointment(int id) { var singleAppointment = (from a in dc.tblAppointments where a.appID == ...
Hi all, What I need is a method that can return a type (no object, cause no casting allowed) following a condition. Here is an example: ??? right (string fullStr, int endPosition) { string tmpStr = ""; tmpStr = fullStr.Substring(endPosition); if(tmpStr.Length == 1) return tmpStr[0]; //return a char!! else return tmpStr; //r...
Is this bad? Or this is very common in PHP framework? For example, in the parent class, there is a save() function which returns the number of rows affected in the database. Then in the child class, I override this function to do some pre-validation, and also would like to simply return a success/failed boolean value. ...
I read somewhere that functions should always return only one type so the following code is considered as bad code: def x(foo): if 'bar' in foo: return (foo, 'bar') return None I guess the better solution would be def x(foo): if 'bar' in foo: return (foo, 'bar') return () Wouldn't it be cheaper memory wise to return a None ...
I know that there are times when using return; can serve a useful purpose in Java, such as in guarding: public void foo(Bar bar) { if(bar == null) return; // bar is not null, go ahead and do stuff with it } But what about just reaching the end of a method with return type void? For example, public void printMenu() {...
I have one method that looks like this: void throwException(string msg) { throw new MyException(msg); } Now if I write int foo(int x, y) { if (y == 0) throwException("Doh!"); else return x/y; } the compiler will complain about foo that "not all paths return a value". Is there an attribute I can add to t...
Take a look at these three classes. Minatchi allows itself to be extended so that its methods' returning type could be extended as well. To illustrate, I used a static method. public class Minatchi<T extends Minatchi<?>>{ static public <T extends Minatchi<?>> List<T> listAll(){ return (List<T>) query(); } } And ...
I'm about to refactor some duplicated code. Two functions both search in a multimap using equal_range(). In a for loop after the call to equal_range() there is a for loop that sets an iterator to equalRange.first with the condition it != equalRange.second. If the correct value is found, the two functions differ. What I would like to do...