C# Object
In C #, the object is a real world unit, for example, chair, car, pen, mobile, laptop etc.
In other words, the object is a unit in which there are states and behaviors. Here, the state means data and behavior means efficiency. Object is a runtime unit, it is built on runtime
An example of a class object is that all the members of the class can be accessed through the object.
Syntax -
Syntax -
Student s1 = new Student();//creating an object of Student
C# Class
class is a group of identical objects, this is a template in which the object is created. This can be fields, methods, constructors etc.
Syntax -
public class Student
{
int id;//field or data member
String name;//field or data member
}
{
int id;//field or data member
String name;//field or data member
}
C# Object and Class Example
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);
}
}
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);
}
}
0 comments:
Post a Comment