C#
Day 1
Lecture1: Basic
Environment
Tools required:
• The .NET Framework is a platform for building, deploying, and
running different types of Web and Desktop based Applications &
Web Services.
• Common Language Runtime (CLR): The .NET Framework contains a
run-time environment known as CLR which runs the codes. It
provides services to make the development process easy.
• Framework Class Library(FCL): It is a library of classes, value types,
interfaces that provide access to system functionality.
• An IDE (Integrated Development Environment) is a tool that helps to
write programs using different programming languages.
Key Organizational Concepts in C#
C# is developed by Anders Hejlsberg at Microsoft in 2000 as a rival to
Java.
• Programs
• Namespaces
• Types
• member
Topic
• C# Environment
• Basic Syntax
• Data Types
• Type Casting
• Variables
• Operators
• Decision Making
• Loops
• Methods
• Arrays
• String
• Class
• Static Keyword
Features of C#
• simple, modern, object-oriented
• type-safe programming language
• component-oriented programming
• garbage collection
• exception handling
Basic Syntax: Write()
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.Write("I’m Jannat Binta Alam. And you?");
}
}
}
Basic Syntax: Read()
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.Write("I’m Jannat Binta Alam. And you?");
Console.Read();
}
}
}
Basic Syntax: Clear()
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.Write("I’m Jannat Binta Alam. And you?");
Console.Read();
Console.Clear();
}
}
}
Comment
• Single Line Comment
// comment
• Multiline Comment
/* first line
last line */
Your First Program
• Program Name: Hello Universe
• Author Name: Jannat Binta Alam
• Task: A Program to Print “Hello Universe”
• Date: 26th October, 2018: 8.30AM
Or 26.10.2018:8.30AM
Problem Set
• Write a program to print “Hello Universe! –Your Name” in console.
Hello Universe!
using System;
class Hello
{
static void Main()
{
Console.WriteLine("Hello Universe!");
Console.ReadKey();
}
}
Hello Universe!
class Hello
{
static void Main()
{
System.Console.WriteLine("Hello Universe!");
System.Console.ReadKey();
}
}
Basic Syntax: BackgroundColor
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
}
}
}
Basic Syntax: Read()
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Read();
}
}
}
Basic Syntax: WriteLine()
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("C#: Learn to Build!");
Console.Read();
}
}
}
Basic Syntax: BackgroundColor
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Clear();
Console.WriteLine("C#: Learn to Build!");
Console.Read();
}
}
}
Basic Syntax: ForegroundColor
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("C#: Learn to Build!");
Console.ReadKey();
}
}
}
Basic Syntax: Beep
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("C#: Learn to Build!");
Console.Beep(2100,1000); //(int frequency, int millisecond)
Console.ReadKey();
}
}
}
Basic Syntax: Color Variable
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
ConsoleColor col = Console.BackgroundColor;
Console.Write(col);
}
}
}
Basic Syntax: Color Variable
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.DarkBlue;
ConsoleColor col = Console.BackgroundColor;
Console.Write(col);
}
}
}
Basic Syntax: Color Variable
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
ConsoleColor col = Console.ForegroundColor;
Console.Write(col);
}
}
}
Basic Syntax: Color Variable
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Green;
ConsoleColor col = Console.ForegroundColor;
Console.Write(col);
}
}
}
Basic Syntax: Color Variable
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
ConsoleColor col = Console.BackgroundColor;
ConsoleColor col1 = Console.ForegroundColor;
Console.Write(col);
Console.Write(col1);
Console.Read();
}
}
}
Basic Syntax: CursorSize
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.CursorSize = 100; //range=1-100
Console.ForegroundColor = ConsoleColor.DarkRed;
Console.Write(("C#: Learn to Build!“);
}
}
}
Basic Syntax: SetWindowSize()
using System;
namespace Basic_syntax
{
class Program
{
static void Main(string[] args)
{
Console.Write(("C#: Learn to Build!“);
Console.SetWindowSize(200, 50); //(width, height); max h=50.
}
}
}
This slide is provided as a course material in the workshop named
“Workshop on C# Programming: Learn to Build”.
Organized by-
East West University Computer Programming Club (EWUCoPC)
Prepared by-
Jannat Binta Alam
Campus Ambassador
Young Engineers Society (YES)
E-mail: jannat.cse.ewu@gmail.com

C# Basic - Lec1 (Workshop on C# Programming: Learn to Build)

  • 2.
  • 4.
    Environment Tools required: • The.NET Framework is a platform for building, deploying, and running different types of Web and Desktop based Applications & Web Services. • Common Language Runtime (CLR): The .NET Framework contains a run-time environment known as CLR which runs the codes. It provides services to make the development process easy. • Framework Class Library(FCL): It is a library of classes, value types, interfaces that provide access to system functionality. • An IDE (Integrated Development Environment) is a tool that helps to write programs using different programming languages.
  • 8.
    Key Organizational Conceptsin C# C# is developed by Anders Hejlsberg at Microsoft in 2000 as a rival to Java. • Programs • Namespaces • Types • member
  • 9.
    Topic • C# Environment •Basic Syntax • Data Types • Type Casting • Variables • Operators • Decision Making • Loops • Methods • Arrays • String • Class • Static Keyword
  • 10.
    Features of C# •simple, modern, object-oriented • type-safe programming language • component-oriented programming • garbage collection • exception handling
  • 11.
    Basic Syntax: Write() usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.Write("I’m Jannat Binta Alam. And you?"); } } }
  • 12.
    Basic Syntax: Read() usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.Write("I’m Jannat Binta Alam. And you?"); Console.Read(); } } }
  • 13.
    Basic Syntax: Clear() usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.Write("I’m Jannat Binta Alam. And you?"); Console.Read(); Console.Clear(); } } }
  • 14.
    Comment • Single LineComment // comment • Multiline Comment /* first line last line */
  • 15.
    Your First Program •Program Name: Hello Universe • Author Name: Jannat Binta Alam • Task: A Program to Print “Hello Universe” • Date: 26th October, 2018: 8.30AM Or 26.10.2018:8.30AM
  • 16.
    Problem Set • Writea program to print “Hello Universe! –Your Name” in console.
  • 17.
    Hello Universe! using System; classHello { static void Main() { Console.WriteLine("Hello Universe!"); Console.ReadKey(); } }
  • 18.
    Hello Universe! class Hello { staticvoid Main() { System.Console.WriteLine("Hello Universe!"); System.Console.ReadKey(); } }
  • 19.
    Basic Syntax: BackgroundColor usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.DarkBlue; } } }
  • 20.
    Basic Syntax: Read() usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.Read(); } } }
  • 21.
    Basic Syntax: WriteLine() usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.WriteLine("C#: Learn to Build!"); Console.Read(); } } }
  • 22.
    Basic Syntax: BackgroundColor usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.DarkBlue; Console.Clear(); Console.WriteLine("C#: Learn to Build!"); Console.Read(); } } }
  • 23.
    Basic Syntax: ForegroundColor usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("C#: Learn to Build!"); Console.ReadKey(); } } }
  • 24.
    Basic Syntax: Beep usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("C#: Learn to Build!"); Console.Beep(2100,1000); //(int frequency, int millisecond) Console.ReadKey(); } } }
  • 25.
    Basic Syntax: ColorVariable using System; namespace Basic_syntax { class Program { static void Main(string[] args) { ConsoleColor col = Console.BackgroundColor; Console.Write(col); } } }
  • 26.
    Basic Syntax: ColorVariable using System; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.DarkBlue; ConsoleColor col = Console.BackgroundColor; Console.Write(col); } } }
  • 27.
    Basic Syntax: ColorVariable using System; namespace Basic_syntax { class Program { static void Main(string[] args) { ConsoleColor col = Console.ForegroundColor; Console.Write(col); } } }
  • 28.
    Basic Syntax: ColorVariable using System; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; ConsoleColor col = Console.ForegroundColor; Console.Write(col); } } }
  • 29.
    Basic Syntax: ColorVariable using System; namespace Basic_syntax { class Program { static void Main(string[] args) { ConsoleColor col = Console.BackgroundColor; ConsoleColor col1 = Console.ForegroundColor; Console.Write(col); Console.Write(col1); Console.Read(); } } }
  • 30.
    Basic Syntax: CursorSize usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.CursorSize = 100; //range=1-100 Console.ForegroundColor = ConsoleColor.DarkRed; Console.Write(("C#: Learn to Build!“); } } }
  • 31.
    Basic Syntax: SetWindowSize() usingSystem; namespace Basic_syntax { class Program { static void Main(string[] args) { Console.Write(("C#: Learn to Build!“); Console.SetWindowSize(200, 50); //(width, height); max h=50. } } }
  • 32.
    This slide isprovided as a course material in the workshop named “Workshop on C# Programming: Learn to Build”. Organized by- East West University Computer Programming Club (EWUCoPC) Prepared by- Jannat Binta Alam Campus Ambassador Young Engineers Society (YES) E-mail: jannat.cse.ewu@gmail.com