Complete Comparison for VB.NET and C#

Complete Comparison for VB.NET and C#


Visual Basic [.NET] (VB.NET) is a multi-paradigm, high-level programming language, implemented on the .NET Framework. Microsoft launched VB.NET in 2002 as the successor to its original Visual Basic language.


C# (pronounced "C-sharp") is an object-oriented programming language from Microsoft that aims to combine the computing power of C++ with the programming ease of Visual Basic. C# is based on C++ and contains features similar to those of Java. C# is designed to work with Microsoft's .Net platform.

VB.Net Namespace


Imports System.Data
Imports System.Data.SqlClient
Imports System.IO


C# Namespace


using System.Data;
using System.Data.SqlClient;
using System.IO;


VB.NET Page Load 

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
      
    End Sub


C# Page Load 


protected void Page_Load(object sender, EventArgs e)
    {     

    }


VB.NET Varibles


Dim str As String
str = "VB.NET"
  
Dim cmd As SqlCommand = New SqlCommand()
Dim con As SqlConnection = New SqlConnection()


C# Varibles

SqlCommand cmd = new SqlCommand();
SqlConnection con = new SqlConnection();
string str="";
str="C#";


VB.NET Database ConnectionString


Dim con As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("dbcon").ConnectionString)
       
con.Open()


C# Database ConnectionString


SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());

        con.Open();


VB.NET If Condition

 Dim s As String = "VB.NET"
        If s = "VB.NET" Then
            Response.Write("Success")
        Else
            Response.Write("Not Success")
        End If


C# If Condition


string s = "C#";
        if (s == "C#")
        { 
            Response.Write("Success");
        }
        else
        {
            Response.Write("Not Success");
        }


VB.NET Function/Methods


Public Sub bind()

    End Sub

Protected Sub bind()

    End Sub

Private Sub bind()

    End Sub


C# Function/Methods

Public void bind()
{
}
Protected void bind()
{
}
Private void bind()
{
} 

VB.NET  WebForm Call

        Response.Redirect("Login.aspx")

C#  WebForm Call

        Response.Redirect("Login.aspx");

VB.NET Image Upload to Server Folder

Dim imgname As String = FileUpload1.PostedFile.FileName

            FileUpload1.SaveAs(Server.MapPath("img/" + imgname))


 C# Image Upload to Server Folder

 String imgname = FileUpload1.PostedFile.FileName;

            FileUpload1.SaveAs(Server.MapPath("img/" + imgname));

VB.NET Access Session

            lbtUsername.Text = Session("username").ToString()

C# Access Session


      lbtUsername.Text = Session["username"].ToString();


VB.NET Access Gridview Events


Protected Sub Button1_Click(sender As Object, e As EventArgs)

        Dim btn As Button = CType(sender, Button)
        Dim row As GridViewRow = CType(btn.NamingContainer, GridViewRow)
        Dim lblAmount1 As String = DirectCast(row.FindControl("Label2"), Label).Text   
    
    End Sub

// Gridview events

        Dim lblid As String = DirectCast(GridView22.Rows(e.RowIndex).FindControl("Label2"), Label).Text


C# Access GridView Events

protected void Button1_Click(object sender, EventArgs e)
    {
        Button btn = (Button)sender;
        GridViewRow row = (GridViewRow)btn.NamingContainer;
        Label lblAmount1 = (Label)row.FindControl("Label2");
    }

 // Gridview events

Label lblid = (Label)GridView1.Rows[e.RowIndex].FindControl("Label2");







1 comment: