Last post Nov 05, 2019 11:53 AM by Chan Leo
Nov 02, 2019 08:08 PM|Chan Leo|LINK
In Vb.Net application there are thousand of pages and controls tht are using this statment and if we are going to convert on each page then its really time consuming, is there any any alternative in c# which can quickly apply with minimum changes and save
Nov 04, 2019 05:22 AM|Yongqing Yu|LINK
In Vb.Net application there are thousand of pages and controls tht are using this statment and if we are going to convert on each page then its really time consuming, is there any any alternative in c# which can quickly apply with minimum changes and save time?
What do you mean by using this statement for thousand of pages and controls you mentioned?
CType(expression,datatype) returns the result of explicitly converting an expression to a specified data type, object, structure, class, or interface.
If you want to replace it with C#, you can refer to the following code：
Dim testNumber As Long = 1000
Dim testNewType As Single = CType(testNumber, Single)
long testNumber = 1000;
float testNewType = System.Convert.ToSingle(testNumber);
Nov 05, 2019 10:52 AM|Chan Leo|LINK
It means that there are lot of pages especially in .aspx pages where CType is used for casting and if we are going to made change on each page when converting the pages to C# then it is very big afford and we have not enough time.
Explicit casting is not solution in my case.that will took long time.We need some quick fix.
Nov 05, 2019 11:13 AM|Khuram.Shahzad|LINK
You can left the implementation of CType because in C# there is not built in function (CType). look at sample code , please note its just implementation of int to decimal conversion you can extend it as per need.
static void Main(string args)
Console.WriteLine("Resullt => "+CType(1, "decimal"));
public static dynamic CType(dynamic expression,string typeName)
if (expression.GetType() == typeof(int))
if (typeName == "decimal")
Nov 05, 2019 11:22 AM|Chan Leo|LINK
Does that means we need to analyze the all types implementation and then made custom code for conversion, does that also means that we do not need any change in all of the existing pages?
Nov 05, 2019 11:40 AM|mbanavige|LINK
CType comes from the VisualBasic assembly.
This assembly is added to vb.net projects automatically so as to provide methods to the vb.net developer that they had historically used.
You can add the VisualBasic assembly to a c# project though as it's really nothing more than a basic method library - no need to try to rewrite it...
Once you've added it, then those method calls will work just fine and you can then take your time converting the old code over to the new more standard methods natively available in c#
Nov 05, 2019 11:53 AM|Chan Leo|LINK
Already remove the VisualBasic assembly that was injected by conversion tool (Visual Studio Extension) and need everything in C#, that is requirement of business.