├── README.md ├── program.cs ├── hello.cs ├── Mathabs.cs ├── mathmax.cs ├── mathmin.cs ├── mathround.cs ├── mathsqrt.cs ├── print.cs ├── add.cs ├── char.cs ├── float.cs ├── intvar.cs ├── var.cs ├── variable.cs ├── double.cs ├── long.cs ├── sys.cs ├── comment.cs ├── concat.cs ├── num.cs ├── plusequal.cs ├── string.cs ├── manyvariables.cs ├── number.cs ├── manynumber.cs ├── application.cs ├── floatdouble.cs ├── demo.cs ├── age.cs ├── concats.cs ├── multiline-comment.cs ├── typecast.cs ├── bool.cs ├── typecasting.cs ├── int.cs ├── plus.cs ├── user-input.cs ├── data.cs ├── datatypes.cs ├── event.cs └── database.cs /README.md: -------------------------------------------------------------------------------- 1 | # C-Sharp 2 | C Sharp Programs 3 | -------------------------------------------------------------------------------- /program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine(3 + 3); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /hello.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace HelloWorld 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine("Hello World!"); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Mathabs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine(Math.Abs(-4.7)); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mathmax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine(Math.Max(5, 10)); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mathmin.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine(Math.Min(5, 10)); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mathround.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine(Math.Round(9.99)); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mathsqrt.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine(Math.Sqrt(64)); 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /print.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int x = 10; 9 | Console.WriteLine(x); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /add.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MyApplication 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | int x = 100 + 50; 10 | Console.WriteLine(x); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /char.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | char myGrade = 'B'; 9 | Console.WriteLine(myGrade); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /float.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | float myNum = 5.75F; 9 | Console.WriteLine(myNum); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /intvar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myNum = 100000; 9 | Console.WriteLine(myNum); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /var.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | string name = "John"; 9 | Console.WriteLine(name); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /variable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myNum = 15; 9 | Console.WriteLine(myNum); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /double.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | double myNum = 19.99D; 9 | Console.WriteLine(myNum); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /long.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | long myNum = 15000000000L; 9 | Console.WriteLine(myNum); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /sys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int x = 5; 9 | int y = 6; 10 | Console.WriteLine(x + y); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /comment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace HelloWorld 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | // This is a comment 9 | Console.WriteLine("Hello World!"); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /concat.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | string name = "John"; 9 | Console.WriteLine("Hello " + name); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /num.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myNum; 9 | myNum = 15; 10 | Console.WriteLine(myNum); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /plusequal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int x = 10; 9 | x += 5; 10 | Console.WriteLine(x); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /string.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | string greeting = "Hello World"; 9 | Console.WriteLine(greeting); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /manyvariables.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int x = 5, y = 6, z = 50; 9 | Console.WriteLine(x + y + z); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /number.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myNum = 15; 9 | myNum = 20; 10 | Console.WriteLine(myNum); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /manynumber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int x, y, z; 9 | x = y = z = 50; 10 | Console.WriteLine(x + y + z); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /application.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.Write("Hello World! "); 9 | Console.Write("I will print on the same line."); 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /floatdouble.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | float f1 = 35e3F; 9 | double d1 = 12E4D; 10 | Console.WriteLine(f1); 11 | Console.WriteLine(d1); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /demo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | Console.WriteLine("Hello World!"); 9 | Console.WriteLine("I am Learning C#"); 10 | Console.WriteLine("It is awesome!"); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /age.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MyApplication 4 | { 5 | class Program 6 | { 7 | static void Main(string[] args) 8 | { 9 | Console.WriteLine("Enter your age:"); 10 | int age = Convert.ToInt32(Console.ReadLine()); 11 | Console.WriteLine("Your age is: " + age); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /concats.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | string firstName = "John "; 9 | string lastName = "Doe"; 10 | string fullName = firstName + lastName; 11 | Console.WriteLine(fullName); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /multiline-comment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace HelloWorld 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | /* The code below will print the words Hello World 9 | to the screen, and it is amazing */ 10 | Console.WriteLine("Hello World!"); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /typecast.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myInt = 9; 9 | double myDouble = myInt; // Automatic casting: int to double 10 | 11 | Console.WriteLine(myInt); 12 | Console.WriteLine(myDouble); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /bool.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | bool isCSharpFun = true; 9 | bool isFishTasty = false; 10 | Console.WriteLine(isCSharpFun); // Outputs True 11 | Console.WriteLine(isFishTasty); // Outputs False 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /typecasting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | double myDouble = 9.78; 9 | int myInt = (int) myDouble; // Manual casting: double to int 10 | 11 | Console.WriteLine(myDouble); 12 | Console.WriteLine(myInt); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /int.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | // Good 9 | int minutesPerHour = 60; 10 | 11 | // OK, but not so easy to understand what m actually is 12 | int m = 60; 13 | 14 | Console.WriteLine(minutesPerHour); 15 | Console.WriteLine(m); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /plus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int sum1 = 100 + 50; // 150 (100 + 50) 9 | int sum2 = sum1 + 250; // 400 (150 + 250) 10 | int sum3 = sum2 + sum2; // 800 (400 + 400) 11 | Console.WriteLine(sum1); 12 | Console.WriteLine(sum2); 13 | Console.WriteLine(sum3); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /user-input.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | // Type your username and press enter 9 | Console.WriteLine("Enter username:"); 10 | 11 | // Create a string variable and get user input from the keyboard and store it in the variable 12 | string userName = Console.ReadLine(); 13 | 14 | // Print the value of the variable (userName), which will display the input value 15 | Console.WriteLine("Username is: " + userName); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /data.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myInt = 10; 9 | double myDouble = 5.25; 10 | bool myBool = true; 11 | 12 | Console.WriteLine(Convert.ToString(myInt)); // Convert int to string 13 | Console.WriteLine(Convert.ToDouble(myInt)); // Convert int to double 14 | Console.WriteLine(Convert.ToInt32(myDouble)); // Convert double to int 15 | Console.WriteLine(Convert.ToString(myBool)); // Convert bool to string 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /datatypes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MyApplication 3 | { 4 | class Program 5 | { 6 | static void Main(string[] args) 7 | { 8 | int myNum = 5; // integer (whole number) 9 | double myDoubleNum = 5.99D; // floating point number 10 | char myLetter = 'D'; // character 11 | bool myBool = true; // boolean 12 | string myText = "Hello"; // string 13 | Console.WriteLine(myNum); 14 | Console.WriteLine(myDoubleNum); 15 | Console.WriteLine(myLetter); 16 | Console.WriteLine(myBool); 17 | Console.WriteLine(myText); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /event.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Web; 7 | using System.Web.Security; 8 | using System.Web.UI; 9 | using System.Web.UI.HtmlControls; 10 | using System.Web.UI.WebControls; 11 | using System.Web.UI.WebControls.WebParts; 12 | using System.Xml.Linq; 13 | 14 | namespace eventdemo { 15 | public partial class treeviewdemo : System.Web.UI.Page { 16 | 17 | protected void Page_Load(object sender, EventArgs e) { 18 | txtmessage.Text = " "; 19 | } 20 | 21 | protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) { 22 | 23 | txtmessage.Text = " "; 24 | lblmessage.Text = "Selected node changed to: " + TreeView1.SelectedNode.Text; 25 | TreeNodeCollection childnodes = TreeView1.SelectedNode.ChildNodes; 26 | 27 | if(childnodes != null) { 28 | txtmessage.Text = " "; 29 | 30 | foreach (TreeNode t in childnodes) { 31 | txtmessage.Text += t.Value; 32 | } 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database.cs: -------------------------------------------------------------------------------- 1 | namespace createdatabase 2 | { 3 | public partial class _Default : System.Web.UI.Page 4 | { 5 | protected void Page_Load(object sender, EventArgs e) 6 | { 7 | if (!IsPostBack) 8 | { 9 | DataSet ds = CreateDataSet(); 10 | GridView1.DataSource = ds.Tables["Student"]; 11 | GridView1.DataBind(); 12 | } 13 | } 14 | 15 | private DataSet CreateDataSet() 16 | { 17 | //creating a DataSet object for tables 18 | DataSet dataset = new DataSet(); 19 | 20 | // creating the student table 21 | DataTable Students = CreateStudentTable(); 22 | dataset.Tables.Add(Students); 23 | return dataset; 24 | } 25 | 26 | private DataTable CreateStudentTable() 27 | { 28 | DataTable Students = new DataTable("Student"); 29 | 30 | // adding columns 31 | AddNewColumn(Students, "System.Int32", "StudentID"); 32 | AddNewColumn(Students, "System.String", "StudentName"); 33 | AddNewColumn(Students, "System.String", "StudentCity"); 34 | 35 | // adding rows 36 | AddNewRow(Students, 1, "M H Kabir", "Kolkata"); 37 | AddNewRow(Students, 1, "Shreya Sharma", "Delhi"); 38 | AddNewRow(Students, 1, "Rini Mukherjee", "Hyderabad"); 39 | AddNewRow(Students, 1, "Sunil Dubey", "Bikaner"); 40 | AddNewRow(Students, 1, "Rajat Mishra", "Patna"); 41 | 42 | return Students; 43 | } 44 | 45 | private void AddNewColumn(DataTable table, string columnType, string columnName) 46 | { 47 | DataColumn column = table.Columns.Add(columnName, Type.GetType(columnType)); 48 | } 49 | 50 | //adding data into the table 51 | private void AddNewRow(DataTable table, int id, string name, string city) 52 | { 53 | DataRow newrow = table.NewRow(); 54 | newrow["StudentID"] = id; 55 | newrow["StudentName"] = name; 56 | newrow["StudentCity"] = city; 57 | table.Rows.Add(newrow); 58 | } 59 | } 60 | } 61 | --------------------------------------------------------------------------------