casting

Performance Hit using CAST() in TSQL (SQL Server)?

We have a SQL generator that emits SQL conditional statements generically for specified fields (which for the sake of discussion: we will label as myField). So, if myField is of type NVARCHAR, we can do a comparison of said field against a string like so: myField = 'foo'. However, this does not work for fields of type NTEXT. Thus, w...

What is the (type) in (type)objectname.var

I am going through a book on C# and have come across something that I can't seem to look up, because I don't know what it is called, or trying to search for something by description. Could some explain to me what is going on, or the meaning behind the "(type)" that comes before a reference to an object as in (int)objectname.variablename...

Is casting could lead to a issue???

Hi all, In one RTOS, i'm debugging one issue which is, program is crashing one point always when it send a 8-bit value (Lets call it 'Int8 rogue_int')to a function (lets call it 'Infected( Int16 )' ) whose definition is taking that variable as 16-bit variable. Before entering to that last function Infected(..), value for 'rogue_int' is ...

When to use a Cast or Convert

I am curious to know what the difference is between a cast to say an int compared to using Convert.toInt32(). Is there some sort of performance gain with using one? Also which situations should each be used for. Currently I'm more inclined to use Convert but I don't have a reason to go either way. In my mind I see them both accomplishin...

cast pointer to functor, and call it

can I do something like: typedef void (*functor)(void* param); //machine code of function char functionBody[] = { 0xff,0x43,0xBC,0xC0,0xDE,.... } //cast pointer to function functor myFunc = (functor)functionBody; //call to functor myFunc(param); ...

[C#] Casting object to generic T

Hello. I'm having a little trouble with some casts that i cant figure out out to solve. I have this interface and the following implementations: public interface IConfigureServiceOnServer { void Configure(Service service); } public sealed class ServiceConfigurator : IConfigureServiceOnServer { ... } I'm loading these types at ...

string to RemoteEndPoint C# by sendto

Hi, How can I convert a string to RemoteEndPoint ? ...

Copying between byte array and unsigned long

What's the best/recommended way to copy data between a byte array and an integer in C? Currently I'm using memcpy, which doesn't feel right to me. A sample of the sort of thing I'm doing is below. struct alpha { unsigned char byte_array[20]; } void function(struct alpha *st) { unsigned long num; /* Do some stuf...

How to literally define an array of decimals without multiple casting?

How can I define an array of decimals without explicitly casting each one? //decimal[] prices = { 39.99, 29.99, 29.99, 19.99, 49.99 }; //can't convert double to decimal //var prices = { 39.99, 29.99, 29.99, 19.99, 49.99 }; //can't initialize... decimal[] prices = { (decimal)39.99, (decimal)29.99, (decimal)29.99, (decimal)19.99, (decima...

DLL Problems Causing Casting Exception

I've been breaking apart a large VS C# project into smaller projects, and while everything worked fine when it was all one project, I'm getting an error now that I've split it apart. There is an exception being thrown when I try a cast, though I haven't changed any of the code. The exception is as follows: InvalidCastException [A...

Javascript/HTML - converting byte array to string

Hi, How do I convert a byte array into a string? I have found these functions that do the reverse: function string2Bin(s) { var b = new Array(); var last = s.length; for (var i = 0; i < last; i++) { var d = s.charCodeAt(i); if (d < 128) b[i] = dec2Bin(d); else { var c = s.ch...

How to covert a sbyte[] to BitArray? C#.Net

I'm trying to integrate two systems that deal with images. One system provides an image as a sbyte[] and the other uses a BitArray. I need to take the data from the sbyte[] and convert it into a BitArray. Anyone know how to do this? Thanks, Paul ...

Check type of object where object may be an int (32 or 64)

I would like to assign the property MyProperty with the parameter id. The MyProperty property is of type Object, and it may be either an Int32 or an Int64. How could I check the type of the MyProperty field and then assign it either id or id cast as an int depending on the underlying type? public void MyMethod(long id) { myCla...

In C#, why does a datatable not know the type collection of rows?

I have recently started .NET programming, and looked at both VB.NET and C#. In VB.NET, a strongly typed Datatable cosisted of a collection of strongly types rows. Therefore, for example, this statement would work: lCustomerTable As CustomerDataSet.CustomerTable lCustomerRow as CustomerDataSet.CustomerTable.CustomerRow lCustomerTable ...

When to catch boost::bad_lexical_cast

From the documentation on the boost site for lexical cast it states that when converting from a numeric type to a string type the conversion can throw a bad_lexical_cast. Clearly in this case we should always handle this exception should it be thrown. My question is, what about the other way around, going from a numeric type to a string...

how to cast bigint to prevent sql injection in php?

i am using php and running sql queries on a mysql server. in order to prevent sql injections, i am using mysql_real_escape_string. i am also using (int) for numbers casting, in the following manner: $desired_age = 12; $query = "select id from users where (age > ".(int)$desired_age.")"; $result = mysql_query($query); that work. But,...

How to cast a GroupedEnumerable?

I am playing about with the IQueryProvider.Execute command and am passing in an expression which is part of my expression tree project. This command gives me back an object which can be either an OrderedEnumerable or a GroupedEnumerable depending on the original expression. A GroupBy expression creates the GroupedEnumerable object. The f...

Cast to user-defined data type in PostgreSQL

I have created a data type called id which consists of two text values: id(text, text) I now need to cast values to this data type before they are inserted into my table. How would I go about doing this? I created the type as follows: CREATE TYPE ID AS(id text, source text); ...

Incorrect results for average distance using Dijkstra (java)

The graph is unweighed, an element of the array of HashSets neighbours[] is a node neighbours[1] is node 1 (they start from 0 mind you) with its unique neighbouring nodes say 2 3 4 5. (so neighbours[5] will contain 1). And I have the following method I did with great deal of help as I dont get the algo much beyond theory. The number it ...

Cast as decimal not giving me correct results

Hello I get a result of 0.00000 from the following cast Secs_in_month = 2592000 total_fault_time_sum = 99 cast(((Secs_in_Month - total_fault_time_sum) / Secs_in_Month) as decimal(18,5)) AS availability the result should be 0.99996 any ideas on what I am doing wrong here ? Many thanks ...