type-conversion

WPF TypeConverter ConvertTo not firing

Hi, I have a dependency property in a class which I need to be converted to a string. I have added the TypeConverty attribute on the property. The type I am converting is the .net Style class. [TypeConverter(typeof(BulletStyleTypeConverter))] public Style BulletStyle { get { return (Style)GetValue(BulletStyleProper...

Conversion constructor vs. conversion operator: precedence

Reading some questions here on SO about conversion operators and constructors got me thinking about the interaction between them, namely when there is an 'ambiguous' call. Consider the following code: class A; class B { public: B(){} B(const A&) //conversion constructor { cout << "cal...

C++ difference between automatic type conversion to std::string and char*

As a learning exercise, I have been looking at how automatic type conversion works in C++. I know that automatic type conversion should generally be avoided, but I'd like to increase my knowledge of C++ by understanding how it works anyway. I have created a StdStringConverter class that can be automatically converted to a std::string, ...

What's the difference between to_string() and as_a(string) in specman?

In Specman I can convert a variable to a string using either: x.to_string(); or x.as_a(string); Is there any difference between the two? If not, why does Specman provide both? ...

Why is implicit conversion allowed from superclass to subclass?

Can someone tell me why the line with "//Compiles" compiles, and why the line with "//Doesn't Compile" does not? I don't understand why A would be implicitly convertible to B, not the other way round. public class SomeClass { static public void Test() { AClass a = new AClass(); BClass b = new BClass(); a = b; // Compiles b...

Automatic type conversion with Castle ActiveRecord properties.

I have a Castle ActiveRecord class with a DateTime property. I am importing data from a text file, and would love to be able to do something like this: string date_started = "09/25/2009"; MyClass myclass = new MyClass; myclass.date_started = date_started; On the final assignment, behind the scenes, it would ideally check the type of d...

Multiplying long values?

class Main { public static void main (String[] args){ long value = 1024 * 1024 * 1024 * 80; System.out.println(Long.MAX_VALUE); System.out.println(value); } } Output is: 9223372036854775807 0 It's correct if long value = 1024 * 1024 * 1024 * 80L;! ...

Three boolean values saved in one tinyint

Hello, probably a simple question but I seem to be suffering from programmer's block. :) I have three boolean values: A, B, and C. I would like to save the state combination as an unsigned tinyint (max 255) into a database and be able to derive the states from the saved integer. Even though there are only a limited number of combinat...

Fixing older program: database text encoding, and incorrect field types.

I'm currently again working on a program from when I was, umm... less capable. It has a number of problems: The database collation is latin1_swedish_ci. I would like to convert it to utf8. How would I do this? The database has some fields that are boolean values stored as 0 or 1. However, the fields are varchars instead of bools. How c...

Confusing type conversion - 2 Bytes to Double

I was recently asked to take over a project in which waveform data is sampled from a power converter and sent to an intelligent agent where calculations are done and the appropriate actions are taken based on the results. The following (java)snippet is what the previous coder used to convert the byte array into an array of doubles: ...

Most succinct way to convert ListBox.items to a generic list

I am using C# and targeting the .NET Framework 3.5. I'm looking for a small, succinct and efficient piece of code to copy all of the items in a ListBox to a List<String> (Generic List). At the moment I have something similar to the below code: List<String> myOtherList = new List<String>(); // Populate our colCriteria ...

How to convert long to LPCWSTR?

Hi, how can I convert long to LPCWSTR in C++? I need function similar to this one: LPCWSTR ToString(long num) { wchar_t snum; swprintf_s( &snum, 8, L"%l", num); std::wstring wnum = snum; return wnum.c_str(); } ...

[C#] Convert string to double with 2 digit after decimal separator

All began with these simple lines of code: string s = "16.9"; double d = Convert.ToDouble(s); d*=100; The result should be 1690.0, but it's not. d is equal to 1689.9999999999998. All I want to do is to round a double to value with 2 digit after decimal separator. Here is my function. private double RoundFloat(double Value) { floa...

Converting an int representing number of cents to money

Like this question, except T-SQL instead of php. 206275947 = 2062759.47 etc. The problem I'm running into is that an attempt to SUM the values in this column is overflowing the integer datatype in SQL. SUM(CONVERT(money,[PaymentInCentsAmt])) Is just tacking on ".00" to the end of the value. What obvious thing am I missing? ...

difference between Convert.ToInt32 and (int)

the following syntax throws an compile time error like Cannot convert type 'string' to 'int' string name=(Session["name1"].ToString()); int i = (int)name; whereas the code below compiles and executes successfully string name=(Session["name1"].ToString()); int i = Convert.ToInt32(name); I would like to know 1) why the compile time ...

Linq to SQL Int16 Gets Converted as Int32 In SQL Command

With the method parameter Int16? id And the Linq to SQL where clause where !id.HasValue || m.Id == id The resulting command text for the condition in the data context is From the visualizer: SELECT [t0].[Id], [t0].[Name], [t0].[IsActive] FROM [Model] AS [t0] WHERE (CONVERT(Int,[t0].[Id])) = @p0 ------------------------------- @p0...

What is the difference between (type)value and type(value) ?

What is the difference between (type)value and type(value) in C++? ...

Converting from One Class to another Class using Xml Serialization in C#

Hi, In our project we are consuming WCF webservices exposed at Central location as services with basicHttpBinding. In client desktop application we need consume those webservices. I am able to generate proxy class using WSDL.exe. But, I need to convert data/class given by the webservice into my local class, for that now I am xmlseri...

Cast function for Hibernate

Hi, all I have tried to cast to float numbers from string in the database fields to compare with another numbers. The field in the database was String type. I have tried to use BETWEEN criteria using cast() as " cast(field, float) BETWEEN 1.003 AND 100.00)" in the where statement. however, it does not help. however, when I tried to ex...

String in scientific notation C++ to double conversion

Hi, I've got a database filled up with doubles like the following one: 1.60000000000000000000000000000000000e+01 Does anybody know how to convert a number like that to a double in C++? Is there a "standard" way to do this type of things? Or do I have to roll my own function? Right now I'm doing sth like this: #include <string> #in...