SQL Server Technology Consulting SQL Server SSIS Snowflake Product Engineering Business Intelligence Solutions Custom Software Development Software Testing QA Microsoft Office Enterprise Software Development Java Web Development Predictive Analytics AI Development Tableau Consulting IoT App Development ML Services Gaming App Cyber Security Laravel Development Ruby on Rails PWA Xamarin App Dynamics 365 Business Central Power BI Consulting Dynamics 365 CRM Customer Insights Customer Service Finance & Operations Dynamics NAV Project Operation Sales Node.js Development NopCommerce OpenAI Development Power Apps Dynamics Consulting Power Platform AR/VR Development Big Data DevOps Consulting Custom Web Development AI/ML Company WooCommerce Full Stack Web Dev Blockchain App React JS Developers React Native Developer Ruby on Rails Developer Shopify Developers UI/UX Developer Vue Developer WordPress Developers Xamarin Developers Android Developer Angular Developers ASP.NET Core Developers Azure Expert Flutter Developers Full Stack Developer HTML CSS Developer Ionic Developers iPhone App Developers JavaScript Developer Joomla Developers Laravel Developer Magento Developers MEAN Stack Developers MS Consultant .NET Developer Node.js Developer Power App Developer Power BI Developer Python Developer

C#/CLASSES AND OBJECTS

C#/CLASSES AND OBJECTS

Everything in C# associated with classes and objects.

Along with its properties methods and constructors and many more things.

This concept is came in C# from real life.

For example in real life car is object and its attributes are weight,color and  method such as drive and brake.

Classes and objects are fundamental concept in C# to concise our code and for better user experience.

A class is a template for creating objects.


CREATE A CLASS

To create a class use class keyword with class name.here is a picture to show how to create a class.

It is not mandatory but its good practice to write first letter in uppercase of name of class.

when we declare any variable in class it becomes field(or attribute) of class.




CREATE A OBJECT

We have above seen how to create a class.Now we see how to create objects of class.

To create an object of Car, specify the class name, followed by the object name, and use the keyword new:and after again class name with paranthesis ().


Here class name is car. we have created object named myobj of  class car with new keyword.



MULTIPLE OBJECTS

We can create multiple objects in a single class but with different object name.



Here we can see two objects of class are cretaed with different names.

If we want to access variables/fields inside a class we use(.)symbol as we can see in above picture we accessed variable with object name (myobj.color).


CLASS MEMBERS

Fields and methods inside a class are known as class members.

We can create multiple fields and methods in a single class.



Here we create two fields with named color and maxSpeed and one method with named (public void fullThrottle()).

We can also leave the fields blank and add value later when we create object .





OBJECT FIELDS/METHODS

variables inside a class called fields and it access with (.)keyword with object name as we seen above.

Methods are used to perform certain actions.

Methods belongs to class and they define how the objects of a class behave.

just like fields we can access method with (.)syntax and remember that we use the name of the method followed by two parentheses () and a semicolon ; to call (execute) the method:

 


 

 

MULTIPLE CLASSES

 

We can also use this way that we create fileds and methods in one class and acess them through another class.

This process is use for better organization of our code that one class conatin all fields and methods while in our Main class we only access them.


In Summary we have seen what is class and objects and how to create them,we also seen concept of multiple objects ,fields and mthods and mutiple classes.

classes define the structure and behavior, while objects are instances of classes that hold specific data and can perform actions defined by the class.Classes and objects are fundamental concepts in C#.

 

 







Previous Next

ssssssStart Your Data Journey Today With MSAInfotech

Take the first step towards data-led growth by partnering with MSA Infotech. Whether you seek tailored solutions or expert consultation, we are here to help you harness the power of data for your business. Contact us today and let’s embark on this transformative data adventure together. Get a free consultation today!

check

We utilize data to transform ourselves, our clients, and the world.

check

Partnership with leading data platforms and certified talents

FAQ Robot

How Can We Help?

Captcha
Back to Top
MSA Infotech ×