C# language Archives - NET-Tutor https://www.aspnettutorials.com/category/c-language/ Blog about programming languages Wed, 13 Jul 2022 09:08:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.1 https://www.aspnettutorials.com/wp-content/uploads/cropped-logo-32x32.png C# language Archives - NET-Tutor https://www.aspnettutorials.com/category/c-language/ 32 32 Standard C# program blocks https://www.aspnettutorials.com/standard-c-program-blocks/ Sat, 22 May 2021 09:00:00 +0000 https://www.aspnettutorials.com/?p=91 Class members are either class or instance members. Static members belong to the class as a whole, and instance members belong to specific objects (class instances).

The post Standard C# program blocks appeared first on NET-Tutor.

]]>
Members
Class members are either class or instance members. Static members belong to the class as a whole, and instance members belong to specific objects (class instances).

Listed below are the types of members that can be contained in a class.

  • Constants. Constant values associated with a class.
  • Fields: variables associated with the class.
  • Methods: actions that can be performed by the class
  • Properties. Actions related to reading and writing named properties of a class.
  • Indexers. Actions that implement the indexing of class instances to refer to them as an array.
  • Events. Notifications that can be created by this class.
  • Operators. Conversion operators and expressions supported by the class.
  • Constructors. Actions required to initialize instances of a class or the class as a whole.
  • Completion methods: actions performed before the final deletion of instances of a class.
  • Types. Nested types declared in a class.

Accessibilities.
Each member of a class has a certain accessibility level. It determines from which area of the program this member can be accessed. There are six levels of accessibility. The following are the accessibility modifiers.

  • public. The access is not limited.
  • private. Access is possible only from this class.
  • protected. Access is possible from this class and classes derived from it.
  • internal. Access is limited to the current assembly (.exe or .dll).
  • protected internal. Access is limited to this class, classes derived from this class or classes in the same assembly.
  • private protected. Access is limited to the given class or classes derived from the given type in the same assembly.

Fields
A field is a variable associated with a particular class or instance of a class.

A field declared with a static modifier is static. A static field defines strictly one storage location. Regardless of how many instances of that class are created, there is only one copy of the static field.

A field declared without static modifier is an instance field. Each instance of a class contains separate copies of all instance fields defined for that class.

Methods
A method is a member that implements a calculation or action that an object or class can perform. Static methods are accessed through the class. Instance methods are accessed through an instance of the class.

A list of parameters can be defined for a method, which represent the values or variable references passed to the method. Methods have a return type, which specifies the type of value calculated and returned by the method. The return value type of a method is void if it does not return a value.

Like types, methods can have a set of type parameters for which type arguments must be specified when calling a method. Unlike types, type arguments can often be derived from method call arguments, in which case they do not need to be specified explicitly.

The method signature must be unique within the class in which the method is declared. The method signature includes the method name, the number of type parameters, and the number, modifiers, and types of method parameters. The method signature does not include the type of the return value.

Parameters
Parameters allow you to pass values or references to variables into the method. Actual values are assigned to method parameters based on the arguments given when the method is called. There are four types of parameters: value parameters, reference parameters, output parameters, and parameter arrays.

The value parameter is used to pass input arguments. The value parameter is mapped to a local variable, which will get its initial value from the value of the argument passed in that parameter. Changes to the value parameter do not affect the argument passed for that parameter.

Value parameters can be made optional by specifying default values for them. Then the corresponding arguments can be omitted.

The post Standard C# program blocks appeared first on NET-Tutor.

]]>
Types and variables https://www.aspnettutorials.com/types-and-variables/ Fri, 23 Apr 2021 08:56:00 +0000 https://www.aspnettutorials.com/?p=88 A type defines the structure and behavior of any data in C#. A type declaration can include its members, the base type, the interfaces it implements

The post Types and variables appeared first on NET-Tutor.

]]>
A type defines the structure and behavior of any data in C#. A type declaration can include its members, the base type, the interfaces it implements, and the operations allowed for that type. A variable is a label that refers to an instance of a particular type.

There are two kinds of types in C#: reference types and value types. Value type variables contain the data directly, and reference type variables store references to the desired data, which are named objects. Two reference type variables can refer to the same object, so it can happen that operations on one variable will affect the object to which the other variable refers. Each variable of value type has its own copy of data, and operations on one variable cannot affect the other (except for the parameter variables ref and out).

The identifier is the name of the variable. The identifier is a sequence of Unicode characters without spaces. An identifier can be a C# reserved word if it is prefixed by @. When interacting with other languages, it can be useful to use a reserved word as an identifier.

Value types in C# are divided into simple types, enum types, struct types, types that allow NULL values, and tuple value types. Reference types in C# are divided into class types, interface types, array types, and delegate types.

C# programs use type declarations to create new types. A type declaration specifies the name and members of the new type. The six categories of types in C# are user-defined: class types, structure types, interface types, enumeration types, delegate types, and tuple value types. You can also declare record types, either record struct or record class. Record types have members synthesized by the compiler. Records are mainly used to store values with minimal associated behavior.

A class type defines a data structure that contains member data (fields) and member functions (methods, properties, etc.). Classes support single inheritance and polymorphism mechanisms, which allow you to create derived classes that extend and refine the definitions of the base classes.

  • The struct type is similar to a class type in that it represents a structure with member data and member functions. But unlike classes, structures are value types and usually do not require allocating memory from the heap. Structure types do not support user-defined inheritance, and all structure types inherit implicitly from the object type.
  • The interface type defines a contract as a named set of open elements. An object of type class or struct that implements an interface must provide implementations for all interface elements. The interface type can inherit from multiple basic interfaces, and class or struct can implement multiple interfaces.
  • The delegate type represents references to methods with a specific parameter list and return value type. Delegates allow methods to be used as entities, storing them in variables and passing them as parameters. Delegates are similar to the function types used in functional languages. Their working principle is similar to function pointers from some languages. Unlike function pointers, delegates are object-oriented and type-safe.
  • The class, struct, interface, and delegate types support universal patterns that allow you to pass other types to them as parameters.

C# supports unidimensional and multidimensional arrays of any type. Unlike the types listed above, array types do not need to be declared before they can be used. Array types can be formed simply by entering square brackets after the type name. For example, int[] is a one-dimensional array of int type values, while int[,] is a two-dimensional array of int type values, whereas int[][] is a one-dimensional array of one-dimensional arrays (or arrays of arrays) of int type values.

The post Types and variables appeared first on NET-Tutor.

]]>
So why is the language still popular? https://www.aspnettutorials.com/why-is-the-language-still-popular/ Tue, 08 Dec 2020 09:05:00 +0000 https://www.aspnettutorials.com/?p=94 The C language is really old, because it appeared back in 1972. As you can see, it was designed with computers of that time in mind

The post So why is the language still popular? appeared first on NET-Tutor.

]]>
The C language is really old, because it appeared back in 1972. As you can see, it was designed with computers of that time in mind, and they were like a modern calculator in terms of functionality. If it was not for the constant support of the language, the language would have long died and everyone would have forgotten about it. Due to the fact that it is constantly evolving, even now it has not lost its power and it is possible to develop on it. The language is low-level, which means it has a good response and rapid execution.

What is interesting, then based on the C language created a huge number of other languages. There is a term: “C-like programming languages”. This definition refers to programming languages that are based on the C language. Some of them are: C++, C#, D, Java, Objective C, PHP, Perl, Scala and hundreds more.

By the way, there are more books on the topics: “C for Dummies”, “C basics”, “C from scratch” than similar books on other languages taken together.

So why is the language still popular?
The language was and will be popular, because on its basis to date built a huge number of projects that require ongoing support and accordingly professionals. In addition, the language is a good language and writing a program in it you get a fairly fast in terms of execution of the program. And of course, the C language for many is like a parent of other languages and many, including universities, prefer to start the path of learning this language.

This is not stupid, because the language has really influenced a lot of modern programming languages and its principles can be found in almost all of today’s newfangled languages.

In general, the language is worth studying at least for the reason that it gives a basic fundamental understanding of how computers and programming languages work. In the future, if you want to go to C++, C#, Java or even Python, you will still find a lot of similarities and learning the next language will obviously be easier for you. So if you haven’t decided whether or not you want to learn C and you’ve never done programming before, our advice to you is to learn C and this course will give you everything you need to learn it.

This knowledge will be useful to you more than once, and the main thing is how proud you will be able to say: “I started to study even with C”.

The post So why is the language still popular? appeared first on NET-Tutor.

]]>
A brief overview of the C# language https://www.aspnettutorials.com/brief-overview-of-the-c-language/ Thu, 24 Sep 2020 08:51:00 +0000 https://www.aspnettutorials.com/?p=82 C# (pronounced "c-sharp") is a modern object-oriented and type-safe programming language. C# allows developers to create different types of secure and reliable applications that run on .NET.

The post A brief overview of the C# language appeared first on NET-Tutor.

]]>
C# (pronounced “c-sharp”) is a modern object-oriented and type-safe programming language. C# allows developers to create different types of secure and reliable applications that run on .NET. C# belongs to the well-known C family of languages, and will seem familiar to anyone who has worked with C, C++, Java, or JavaScript. Here is an overview of the main components of C# 8 and earlier. If you want to learn the language with interactive examples, we recommend working through the introductory C# manuals.

C# is an object-oriented, component-oriented programming language. C# provides language constructs to directly support this operating concept. This makes C# suitable for creating and applying software components. Since its inception, C# has been enriched with features to support new workloads and modern software development guidelines. C# is basically an object-oriented language. You define types and their behavior.

Here are just a few features of C# that allow you to create robust and resilient applications. Garbage collection automatically frees memory occupied by unreachable unused objects. Types that allow null provide protection against variables that do not reference allocated objects. Exception handling provides a structured and extensible approach to error detection and recovery. Lambda expressions support functional programming techniques. LINQ syntax creates a generic template for handling data from any source. Language support for asynchronous operations provides a syntax for creating distributed systems. C# has a Uniform Type System. All C# types, including primitive types such as int and double, inherit from a single root type object. All types use a common set of operations, and values of any type can be stored, transferred, and handled in a similar way. Moreover, C# supports both user-defined reference types and value types. C# allows you to dynamically allocate objects and store simplified structures in a stack. C# supports universal methods and types that provide enhanced type safety and performance. C# provides iterators that allow collection class developers to define custom behaviors for client code.

C# emphasizes version control to ensure program and library compatibility over time. Version control issues have significantly influenced aspects of C# development such as separate virtual and override modifiers, rules for allowing overloading of methods, and support for explicitly declaring interface members.

The post A brief overview of the C# language appeared first on NET-Tutor.

]]>
.NET Architecture https://www.aspnettutorials.com/net-architecture/ Sat, 12 Oct 2019 08:54:00 +0000 https://www.aspnettutorials.com/?p=85 C# programs run on .NET, a virtual runtime system that calls the Common Language Runtime (CLR) and a set of class libraries.

The post .NET Architecture appeared first on NET-Tutor.

]]>
C# programs run on .NET, a virtual runtime system that calls the Common Language Runtime (CLR) and a set of class libraries. The CLR environment is Microsoft’s implementation of the Common Language Infrastructure (CLI), an international standard. The CLI is the basis for creating runtime and development environments in which languages and libraries work transparently with each other.

Source code written in C# is compiled into an intermediate language (IL) that conforms to the CLI specifications. The IL code and resources, including bitmaps and strings, are stored in an assembly, usually with a .dll extension. An assembly contains a manifest with information about the types, version, language, and regional parameters for that assembly.

When a C# program runs, the assembly is loaded into the CLR environment. The CLR environment performs JIT compilation from IL code into machine language instructions. The CLR environment also performs other operations such as automatic garbage collection, exception handling, and resource management. The code executed by the CLR environment is sometimes called “managed code.” “Unmanaged code” is compiled into a platform-specific machine language.

Providing interoperability between languages is a key feature of .NET. The IL code created by the C# compiler conforms to the Common Type Specification (CTS). IL code created from C# code can interoperate with code created from the .NET versions of F#, Visual Basic, and C++. There are more than 20 other languages compatible with CTS. One assembly can contain several modules written in different .NET languages, and all types can reference each other as if they were written in the same language.

In addition to runtime services, .NET also includes extended libraries. These libraries support many different workloads. They are organized into namespaces that provide a variety of useful features, from file input and output operations to string management and XML parsing, to web application platforms to Windows Forms controls. Typically, C# applications make heavy use of the .NET class library for typical tasks.

The post .NET Architecture appeared first on NET-Tutor.

]]>