Tuesday 5 April 2022

Learn Together C#

 C#

C# is a Object Oriented Programming language which is created by Microsoft and runs on .NET framework. First version of C# is released in 2002.

C# is used for:

  • Mobile applications
  • Desktop applications
  • Web applications
  • Web services
  • Web sites
  • Games
  • VR
  • Database applications
  • Distributed applications
  • And much, much more!
C# is designed for CLI (Common Language Infrastructure). CLI is a specification that describes executable code and runtime environment.
C# programming language is influenced by C++, Java, Eiffel, Modula-3, Pascal etc. languages.
Anders Hejlsberg is known as the founder of C# language. 

C# types are divided into 2 broad categories 
1.       Value types- int, float, double, structs, enums etc.  (default value some form of value) 
2.       Reference types – Interface, Class, delegates, arrays etc.   (default value is null)

Built in types

·         Boolean type - Only true or false
·         Integral type - sbyte, byte, short, int, long
·         Float type - float(7 precision values), double (16 precision values)
·         Decimal type (26-28 precision values)

Datatypes

Data Type

Size

Description

int

4 bytes

Stores whole numbers from -2,147,483,648 to 2,147,483,647

long

8 bytes

Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

float

4 bytes

Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits

double

8 bytes

Stores fractional numbers. Sufficient for storing 15 decimal digits

bool

1 bit

Stores true or false values

char

2 bytes

Stores a single character/letter, surrounded by single quotes

string

2 bytes per character

Stores a sequence of characters, surrounded by double quotes


int
Integer data 

Printing statement

Console.Write(" ");  statement is used to print the statement and cursor stay on the same line.
Console.WriteLine(" "); statement is used to print the statement and cursor go to the next line.

Input statement

Console.Read(" "); statement is used to read the single statement 
Console.ReadLine(" "); statement is used to read the multiple statements

Difference between Java and C#

No.

Java

C#

1)

Java is a high level, robust, secured and object-oriented programming language developed by Oracle.

C# is an object-oriented programming language developed by Microsoft that runs on .Net Framework.

2)

Java programming language is designed to be run on a Java platform, by the help of Java Runtime Environment (JRE).

C# programming language is designed to be run on the Common Language Runtime (CLR).

3)

Java program extension is .java

C# program extension is .cs

4)

Java type safety is safe.

C# type safety is unsafe.

5)

In java, built-in data types that are passed by value are called primitive types.

In C#, built-in data types that are passed by value are called simple types.

6)

Arrays in Java are direct specialization of Object.

Arrays in C# are specialization of System.

7)

Java does not support conditional compilation.

C# supports conditional compilation using preprocessor directives.

8)

Java doesn't support goto statement.

C# supports goto statement.

9)

Java doesn't support structures and unions.

C# supports structures and unions.

10)

Java supports checked exception and unchecked exception.

C# supports unchecked exception.

11)

Printing statement is System.out.Println(“ ”);

Printing statement is Console.WriteLine(“ “);

12)

Input statement in java, we should first import the scanner statement and Scanner object should be created

Input statement in C#, we should use Console.ReadLine();


Access modifiers

public

The type or member can be accessed by any other code in the same assembly or another assembly that references it. The accessibility level of public members of a type is controlled by the accessibility level of the type itself.

private

The type or member can be accessed only by code in the same class or struct.

protected

 The type or member can be accessed only by code in the same class, or in a class that is derived from that class.

internal

The type or member can be accessed by any code in the same assembly, but not from another assembly. In other words, internal types or members can be accessed from code that is part of the same compilation.

protected internal

The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived class in another assembly.

private protected 

The type or member can be accessed by types derived from the class that are declared within its containing assembly.





No comments:

Post a Comment

SQL & PySpark Comparison

  SQL & PySpark Comparison Consept SQL PySpark Select SELECT column(s) From table SELECT * FROM table; df.select("column(s)") ...