Showing posts with label Difference. Show all posts
Showing posts with label Difference. Show all posts

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");







What is the Difference between Eval() and Bind Methods




       Eval()        Bind()  
1
Eval() Supports  one way Binding only.
Bind() Supports Two Way Binding.
2
Only Read data from Columns
Bind() we can Read & Write data From Column.
3
Eval() Control like the GridView or the FormView display Read only data using a label control
Bind () proper type of datasource, it will pull the altered values out of the GridView or other control 
4
Eval() Use without id control.
Ex:
<table><tr><td>
<%#Eval("username")%>
</td></tr></table>
        
Bind() Use Any Like any  Controls.
Ex:
<ItemTemplate>
                        <asp:Label ID="lblUsername" runat="server" Text='<%# Bind("username") %>'></asp:Label>
</ItemTemplate>








Difference Between For Loop and ForEach Loop Using C#



Difference Between For Loop and ForEach Loop



       For Loop        ForEach Loop   
1
For Loop Variable Always int Only.
ForEach Loop Variable Same as Type of Values Under Array
2
For loop Iterates a Statement or a Block of Statements Repeatedly until a Specified Expression Evaluates to False.
For-each loop is used to Iiterate through the Items in Object Collections, List Generic Collections or Array List Collections.
3
For Loops are Faster Than For Each Loop.
For Each Loop are Slower Than For Loop.
4
Need To Loop Bounds (Minimum,Maximum).

Ex:

int count=0;
int j;
for(int i=0;i<=5;i++)
{
   j=count+1;
}

No Need To Loop Bounds Minimum or Maximum.

EX:

int z=0;
int [] a=new int[]      {0,1,2,3,4,5}; 
   foreach(int i in a)
    {
    z=z+1;
    }















Difference Between Primary Key and Foreign Key in SQL


Difference Between Primary Key and Foreign Key 



       Primary Key        Foreign Key    
1
Primary Key Can Not Accept Null Values. 
Foreign Key Can Accept Multiple Null Values. 
2
Only One Primary Key in a Table. 
More than One Foreign Key in a Table. 
3
Primary Key Uniquely Identify a Record in the Table
Foreign Key is a Field in the Table that is Primary Key in Another Table
4
Primary Key is Clustered Index.
Ex:
CREATE TABLE [country] (
    [id]      INT          IDENTITY (1, 1) NOT NULL,   
    [name] VARCHAR (50) NOT NULL,  
  UNIQUE NONCLUSTERED ([name],
    CONSTRAINT [PK_country] PRIMARY KEY CLUSTERED ([id])

);
Foreign Key is Non-Clustered Index.
Ex:
CREATE TABLE [reg] (   
    [country]  VARCHAR (50) NOT NULL,
    [name]     VARCHAR (50) NOT NULL,
    CONSTRAINT [FK_reg_country] FOREIGN KEY ([name]) REFERENCES [dbo].[country] ([name])

);