Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
35 views

C# Presentation

Uploaded by

yashthakare9267
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

C# Presentation

Uploaded by

yashthakare9267
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 8

C# Structure and

Classes Object

Himani Shyam Sonar


Sonali Aadinath Wankhede
C# Structure (Description):
Description about the keywords which used in C# program

• Class: class is a built in keyword which is used to define a class in


the C# program.
• Program: this is the class name. A class is blueprint or template
from which objects are created. It can have data members and
methods. Here, it has only Main method().
• Static: static keyword means object is not required to access static
members. So it saves memory.
• Void: is the return type of the method name. It does’t return any
value. In such case, return statement is not required.

Main: is the method name. It is the entry point for any C# program. Whenever we run the
C# program, Main() method is invoked first before any other method. It represents start up of
the program.

String[] args: is used for command line arguments in C#. While running the C# program,
we can pass values. These values are known as arguments which we can use in the program.

System.Console.WriteLine (“Hello World”): Here System is the namespace.


Console is the class defined in System namespace. The WriteLine() is the static method of
Console class which is used to write the text on the console.
Simple C# Example

class Program
{
Static void Main (String[] args)
{
System.Console.WriteLine (“Hello world”);
}
}

Output:
Hello world
Class:
Class is a group of similar objects. It is a template from which object are created. It can have
fields, methods, consturctors etc.
Simply the class is the collection of data members and the member functions it is known as
class.

Syntax for creating class:

Class class_name
{
//block of code
}
Object:
• Object is nothing but the real world entity, for example, chair, car, pen, mobile etc
• Object is an entity that has state and behavior. Here state means data and behavior means
functionality
• It is runtime entity, it is created at runtime.
• Object is an instance of a class. All the members of the class can be accessed through
object.

Creating an object :

Student S1= new Student();

Here, in the above object creation Student is a class name and S1 is a object name and in that
example Student(); this is default constructor called.
C# Object and Class Example:
using System;
public class Student
{
int id;
String name;
public static void Main (String[] args)
{
Student s1 = new Student();
s1.id=101;
s1.name=“Ramesh Gangaram”;
Console.WriteLine(s1.id);
Console.WriteLine(s1.name);
}
}

Output:
101
Ramesh Gangaram
THANK
YOU

You might also like