ankitweblogic logo
W e b t u t o r i a l s

Visual Studio.NET IDE

Define C#.NET

C# Comment

C# Variables

C# Data Types

C# Escape Sequence

C# Operators


Format String

Operator Precedence

C# Keywords

Constant Variable

Type Conversion

Flow Control

Exercise Loops & Nested Loop

C# Arrays

C# Strings

User-Define Methods

Variable Scope

C# Enumerations

C# Structure

C# Exception Handling

Object Oriented Programming

C# Classes

Constructor & Destructor

C# Inheritance

C# Polymorphism

C# Operator Overloading

C# Interface

Abstract Classes & Methods

Sealed Classes, Methods

C# Properties

C# Indexer

C# Delegates

C# Generics

C# Collection


C#.Net Classes and Class Members

Class is a user defined data type, grouping variables of different data types, methods, properties etc. By default the access modifier of a class is internal, means, the code can be accessed within the current project. However, we can specify the class as public also. Classes can no way be private or protected. These modifiers are used with the class members not with the class.

Note: The compiler will not allow a derived class to be more accessible than its base class. This means that an internal can inherit from a public base, but a public class can’t inherit from an internal class.

Partial Classes
In a situation, where multiple developers need to access to the same class, or in the situation where a code generator, is generating a part of a class, then having the class in multiple files can be beneficial. In that situation, we can use the concept of partial classes.

Static Classes
If a class contains nothing but static methods and properties, the class itself can become static. An instance of the class can never be created. By using the static keyword, the compiler can help by checking that instance members are never accidentally added to the class. If they are, a compile error happens. This can help guarantee that an instance is never created. The syntax for a static class looks like this:

    static class area
        public static void method1()
            Console.WriteLine("Method 1");
    class Program
        static void Main(string[] args)
Updated: 06-Feb-19