0% found this document useful (0 votes)
41 views2 pages

VB Vs C#

This document compares and contrasts data types and type conversion in VB.NET and C#. It lists the basic value and reference types in each language like integers, floats, strings, and objects. It also shows examples of using GetType, TypeOf/typeof, and type conversion methods like CType, CInt, and casting.

Uploaded by

vandana651
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

VB Vs C#

This document compares and contrasts data types and type conversion in VB.NET and C#. It lists the basic value and reference types in each language like integers, floats, strings, and objects. It also shows examples of using GetType, TypeOf/typeof, and type conversion methods like CType, CInt, and casting.

Uploaded by

vandana651
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

VB.

NET Program Structure Imports System Namespace Hello Class HelloWorld Overloads Shared Sub Main(ByVal args() As String) Dim name As String = "VB.NET" 'See if an argument was passed from the command line If args.Length = 1 Then name = args(0) Console.WriteLine("Hello, " & name & "!") End Sub End Class End Namespace VB.NET } }

C# using System; namespace Hello { public class HelloWorld { public static void Main(string[] args) { string name = "C#"; // See if an argument was passed from the command line if (args.Length == 1) name = args[0]; Console.WriteLine("Hello, " + name + "!"); }

Comments // Single line /* Multiple line */ /// XML comments on single line /** XML comments on multiple lines */ Data Types Value Types bool byte, sbyte char (example: 'A') short, ushort, int, uint, long, ulong float, double decimal DateTime (not a built-in C# type) Reference Types object string

C#

' Single line only Rem Single line only VB.NET Value Types Boolean Byte Char (example: "A"c) Short, Integer, Long Single, Double Decimal Date Reference Types Object String Dim x As Integer Console.WriteLine(x.GetType()) ' Prints System.Int32 Console.WriteLine(GetType(Integer)) ' Prints System.Int32 Console.WriteLine(TypeName(x)) ' Prints Integer

C#

int x; Console.WriteLine(x.GetType()); // Prints System.Int32 Console.WriteLine(typeof(int)); // Prints System.Int32 Console.WriteLine(x.GetType().Name); // prints Int32

' Type conversion // Type conversion Dim d As Single = 3.5 float d = 3.5f; Dim i As Integer = CType(d, Integer) ' set to 4 int i = (int)d; // set to 3 (truncates decimal) (Banker's rounding) i = CInt(d) ' same result as CType i = Int(d) ' set to 3 (Int function truncates the

You might also like