This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Thursday, September 26, 2019

c# asp.net simple programs list


today learn  c# sample programs c#.net programming language it is a .net framework usually Microsoft corporation.
Let's see the list of top C# programs. Then a c# asp.net Interview Question and answer click this link.https://qnainterviewa.blogspot.com/2019/09/c-aspnet-interview-questions-and-answers.html







1.C# Hello Word Program

using System;

namespace HelloWorldApplication {
   class HelloWorld {
      static void Main(string[] args) {
         /* my first program in C# */
         Console.WriteLine("Hello World");
         Console.ReadKey();
      }
   }
}







2.C# Object And Class Program

using System;  
   public class Student  
    {  
        int id;//data member (also instance variable)    
        String name;//data member(also instance variable)    
         
    public static void Main(string[] args)  
        {  
            Student s1 = new Student();//creating an object of Student    
            s1.id = 101;  
            s1.name = "Sonoo Jaiswal";  
            Console.WriteLine(s1.id);  
            Console.WriteLine(s1.name);  
  
        }  
    }  







3.C# Parameter Function Program

using System;  
namespace FunctionExample  
{  
    class Program  
    {  
        // User defined function without return type  
        public void Show() // No Parameter  
        {  
            Console.WriteLine("This is non parameterized function");  
            // No return statement  
        }  
        // Main function, execution entry point of the program  
        static void Main(string[] args)  
        {  
            Program program = new Program(); // Creating Object  
            program.Show(); // Calling Function             
        }  
    }  
}  






4. C# String Program

using System;

namespace StringApplication {

   class Program {
   
      static void Main(string[] args) {
         //from string literal and string concatenation
         string fname, lname;
         fname = "Rowan";
         lname = "Atkinson";
   
         char []letters= { 'H', 'e', 'l', 'l','o' };
         string [] sarray={ "Hello", "From", "Tutorials", "Point" };
         
         string fullname = fname + lname;
         Console.WriteLine("Full Name: {0}", fullname);
         
         //by using string constructor { 'H', 'e', 'l', 'l','o' };
         string greetings = new string(letters);
         Console.WriteLine("Greetings: {0}", greetings);
         
         //methods returning string { "Hello", "From", "Tutorials", "Point" };
         string message = String.Join(" ", sarray);
         Console.WriteLine("Message: {0}", message);
         
         //formatting method to convert a value
         DateTime waiting = new DateTime(2012, 10, 10, 17, 58, 1);
         string chat = String.Format("Message sent at {0:t} on {0:D}", waiting);
         Console.WriteLine("Message: {0}", chat);
      }
   }
}



5.C# Vairable Program

A variable is a name given to a storage area that is used to store values of various data
ypes. Each variable in C# needs to have a specific type, which determines the size and
layout of the variable's memory.

using System;

namespace VariableDefinition {
   class Program {
      static void Main(string[] args) {
         short a;
         int b ;
         double c;

         /* actual initialization */
         a = 10;
         b = 20;
         c = a + b;
         Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c);
         Console.ReadLine();
      }
   }
}








6. Write a program to demonstrate Client Side State Management In C#

A.

Viewstate

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class ClientSideStateMgntVS : System.Web.UI.Page

{


{

if (!IsPostBack)

{

ViewState["PageHitCounter"] = 0;

}

}


protected void btnPageHitCounter_Click(object sender, EventArgs e)

{

ViewState["PageHitCounter"] = Convert.ToInt32(ViewState["PageHitCounter"]) + 1; 
Response.Write("The number of postbacks are - " + ViewState["PageHitCounter"].ToString());

 
}

}


B.Query String:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class QSWF2 : System.Web.UI.Page

{



 
protected void Page_Load(object sender, EventArgs e)

{

//TextBox1.Text = Request.QueryString["Parameter"].ToString();


}

protected void Button1_Click(object sender, EventArgs e)

{

Response.Redirect("menu.aspx?category=vegfood");



}

}




7. Write a program to demonstrate Delegates in c#



using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace AssgnPrograms

{

/*A delegate is a type safe a function pointer that can reference a method that has the same signature as that of the delegate.*/ public delegate void MyDelegate(string text);

class DelegateAssgn15

{

public static void ShowText(string text)


{

Console.WriteLine(text);


}

static void Main(string[] args)


{

MyDelegate d = new MyDelegate(ShowText);
 

d("Hello World...");

 
Console.ReadLine();


}

}

}







8.Write a program to demonstrate Polymorphism

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace AssgnPrograms

{

public class clsShape

{

public int _radius = 5;


public virtual double getArea()

{

return 0;

}

}

public class clsCircle : clsShape

{

public override double getArea()

{

return 3.14 * _radius * _radius;

}
 

}


public class clsSphere : clsShape

{

public override double getArea()

{

return 4 * 3.14 * _radius * _radius;

}

}

class PolyMAssgn7

{

static void Main(string[] args)

{

clsShape objShape1 = new clsCircle();

clsShape objShape2 = new clsSphere();

Console.WriteLine("Radius of a Cirle is - {0}", objShape1.getArea()); 
Console.WriteLine("Radius of a Sphere is - {0}", objShape2.getArea()); Console.ReadLine();



}

}

}


9.Write a program to demonstrate the database in c#(Access Database)

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.Data.OleDb;


namespace AccessAssgn

{

public partial class Form1 : Form

{


OleDbConnection con = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0;Data Sourc e =C:\Users\ASUS\Documents\MyDB.accdb");



public Form1()

{

InitializeComponent();

}



private void Form1_Load(object sender, EventArgs e)

{
 

}

 
private void button1_Click(object sender, EventArgs e)

{

OleDbCommand cmd = con.CreateCommand();

con.Open();

cmd.CommandText = "Insert into Student(FirstName,LastName)Values('" + textBox1.Text + "','" + textBox2.Text + "')";

cmd.Connection = con;

cmd.ExecuteNonQuery();

MessageBox.Show("Record Submitted", "Congrats");

con.Close();

}

}

}

10. C# Array Program

using System;  

public class ArrayExample  
{  
    public static void Main(string[] args)  
    {  
        int[] arr = { 10, 20, 30, 40, 50 };//Declaration and Initialization of array  
   
        //traversing array  
        for (int i = 0; i < arr.Length; i++)  
        {  
            Console.WriteLine(arr[i]);  
        }  
    }  
}  



11.C# Data Type Program

The C# language comes with a set of Basic data types. These data types are used to build
values which are used within an application. Let's explore the basic data types available in
C#. For each example, we will modify just the main function in our Program.cs file.

namespace Tutlane

{

    class Program

    {

        static void Main(string[] args)

        {

            int number = 10;

            string name = "Suresh Dasari";

            double percentage = 10.23;

            char gender = 'M';

            bool isVerified = true;

        }

    }

}






No comments:

Post a Comment