I saw that there is 2 methods to cast an object :
foo.asInstanceOf[Bar]
(foo: Bar)
When I tried I found that as asInstanceOf don't use the implicit conversions whereas the other one do.
So what are the differences of behavior between this 2 methods ? And where it's recommended to use one over the other ?
Thank you.
...
Hi,
this is my first WCF service. I defined a response message that derives from a Dictionary like this:
[CollectionDataContract(ItemName = "Product", KeyName = "ProductNumber", ValueName = "ProductName")]
public class GetAvailableProductsResponse : Dictionary<string, string> { }
When I try to run the following code in a service opera...
I usually use C type casting in C/C++ code. My question is, does adding the "const" keyword in the casting type mean anything to the result?
For example, I can think up several scenarios:
const my_struct *func1()
{
my_struct *my_ptr = new my_struct;
// modify member variables
return (const my_struct *)my_ptr;
// return my...
In the controller:
public ActionResult Index()
{
ViewData["page"] = 0;
return View(data);
}
public ActionResult More(long page = 0)
{
ViewData["page"] = page;
return View(data);
}
So, I have two views: Index.aspx and More.aspx. I created a partial view (PartialView.ascx) that is used in both of the views. Inside the p...
Using a case construct for type-safe casting is easily done in scala. The following code ensures that square gets only called on objects which have an according type.
class O
class A extends O {
def square(i: Int):Int = { i*i }
}
class B extends O {
def square(d: Double):Double = { d*d }
}
class C extends O {}
def square(o: O) ...
Why does THIS not work when called via e.g. wd(1) (it always returns '-2')?
$zoom=$user['zoom'];
function wd($hrs){
return $hrs*$zoom-2;
}
But THIS works fine:
function wd($hrs){
return $hrs*30-2;
}
Assuming this was a casting problem, I tried all sorts of variations like
(int)$hrs * ((int)$zoom)
or
(int)$hrs * (float)$zoom...
Hi,
what, if at all possible, would be a good solution to implement the following desired functionality where I want to:
Cast the return type of a routine to the type of the routine parameter, e.g.,
// Foo and Bar are two types of Common
interface Common{}
interface Foo extends Common {}
interface Bar extends Common {}
// Examp...
I have a list view with a HyperLink control within the ItemTemplate. I want to display the link if a returned value is 0 (false), and not display the link if it is 1 (true).
So far I have this:
<asp:HyperLink runat="server" ID="lnkReview"
NavigateUrl='<%# Eval("EnquiryID", @"selectcompany.aspx?enq={0}")%>'
Text="Review Enquiry"
V...
If a class has a single argument constructor my understanding is it is implicitly convertible by the constructor to the type of the argument in appropriate contexts. Defining a conversion operator also makes a class convertible to another type. Questions
Does the conversion operator ever get called implicitly?
If both a single argume...
Hi,
static int
write_stream(const void *buffer, size_t size, void *app_key)
{
char *stream = (char *)app_key;
return 0;
}
what am I doing wrong here? Why pointer casting does
not result in a copying of (size_t size) bytes from buffer into the
stream defined by app_key?
Thanks
am calling this function as argument of anot...
So I'm just learning C#, and came across something that I find odd... I'm playing with delegates and have creates a delegate DelegateReturnsInt. Now, When I use a foreach loop, the book shows to use it like this:
foreach(DelegateReturnsInt del in theDelegate.getInvocationList())
now I know that getInvocationList() returns an Array of ...
Is there an C++ casting operator (or combination thereof) equivalent to the old-style cast below:
struct MyStruct {
int i;
int j;
int k;
};
void do_something_with_mystruct( MyStruct ms ) {
...
};
int main( int argc, char** argv ) {
do_something_with_mystruct( (MyStruct){1,2,3} );
};
...
Hi
is there an easy in Java to convert primitive class objects into object class objects? Given a class Class cl, I want to convert it into a Class that has no primitives. Eg.
Class<?> cl = int.class;
...
if (cl.isPrimitive()) {
cl = Object of primitive
}
...
cl == Integer.class
I would like a method that does that for all primit...
Possible Duplicate:
Casting: (NewType) vs. Object as NewType
In C#, why ever cast reference types when you can use "as"?
Casting can generate exceptions whereas "as" will evaulate to null if the casting fails.
Wouldn't "as" be easier to use with reference types in all cases?
eg:
MyObject as DataGridView
rather than,
(...
Hi,
I'm working with a fairly complex Javascript program wich, at a given point, returns some nested anonymous functions.
Sometimes, when I try to "apply" one of such anonymous functions ("f" in this example)...
f.apply (this.context, args)
...I get an "f.apply is not a function" error.
It's weird, because alert(f) displays the fun...
I have an NSArray that contains two types of objects. Lets call them Apple and Orange.
Apple *myApple = [self.searchQueryResults objectAtIndex:indexPath.row];
When I am building my cell's I don't know what type is in my array, apples or oranges. How can I use the generic id type to store the object, and then cast appropriately?
...
I find myself casting return types alot to silence compiler warnings and it always makes me feel like i'm doing something wrong.
This example is Objective-c
const char *strBuf = [anNString UTF8String];
[anOutputStream write:strBufr maxLength:len];
This goves me a compiler warning as
-UTF8String returns const char * and -write:maxLe...
Hello,
I need a way to get a pointer to the start of an object in C++. This object is used inside a template so it can be any type (polymorphic or not) and could potentially be an object that uses multiple inheritance.
I found this article which describes a way to do it (see the section called "Dynamic Casts") using typeid and a dynami...
I am fairly new to Objective-C. Currently porting my own library from C#/Java to objective C.
I now run into a very strange problem for me.
I have a NSArray with several Note objects. I want to transpose on of these notes:
//Note.h
- (Note *) transpose: (int) semitones;
//Main
NSArray *notes = [get it from somewhere];
Note *tra...
Hello.
I have a product class in C# that inherits from another product class
using ExternalAssemb.ProductA;
public class MyProduct : ProductA
{
//....
}
I'm trying to do an explicit cast from ProductA that is in a DLL I reference but it's telling me it's unable to cast
MyProduct myProduct = (MyProduct)productAobject;
Result::...