Skip to content

Instantly share code, notes, and snippets.

@kironroy kironroy/csharp.md
Last active Feb 8, 2020

Embed
What would you like to do?
Database Info updated

c sharp logo

Shortcuts

Database Info

C# Topics

C# Notes

C# Web API

C# Console Applications

Open Source

C# Code Snippets for VS


Articles on DEV

Kiron Roy's DEV Profile

apilogo

Back to Shortcuts

Web API


c sharp logo

Back to Shortcuts

Console Programs on Repl.it


github logo


ASP .NET Framework / .NET Core


Windows Forms


Windows Presentation Foundation


c sharp logo

Back to Shortcuts

Notes

C# = is a programming language created by Anders Hejlsberg for Microsoft It created around 2000. .NET = is a framework for creating Windows Applications. Other languages are supported by the framework, like F# and VB NET

  • NET has two elements:
    • Common Language Runtime (CLR): The C# language is compiled to IL code (Intermediate Language).
    • In turn, the CLR translates this IL code to native code at runtime. This is known as Just In Time compilation (JIT)

Main Method = Is the entry point of the application. It is a "quarter back method" it tells what the other methods should do (Console Apps)

Solution = is a container that holds different projects

Assembly = is a single unit of .NET application deployments

Namespace = is a collection of classes

Classes = see further down

Using statements = shortcut code

using { ... } Using statement usually go with Interfaces (IDisposable).

  • A using statement shuts down the class at the end of a } as well as shutting down a connection to a database

References = bring in code

Static Classes = one copy for the entire lifetime of the application. Storing data inside a static class is not a good idea, because it increases the application's memory footprint. They aren't instantiated

  • Static means “associated with the class, not an instance”.
  • Static member is always accessed by the class name, rather than the instance name, like Forest.Area.
  • Static method cannot access non-static members.
  • Static constructor is run once per type, not per instance. It is invoked before the type is instantiated or a static member is accessed.

Instantiated Classes

Auto Properties = are more common because auto-properties target many types of applications WinForms, WPF, ASP.NET MVC...

Constructor = (ctor) is a method that is not static. It is part of the instantiated class. A constructor is a special type of method when a "car/house" (object) is built. It does not return anything

Method overloading

Extension Methods

Inheritance

Articles

Interface

Articles

Abstract Classes

Abstract Classes and Interface

Value Types: hold actual data

  • int
  • double
  • bool
  • char

Reference Types: refer to a location in memory

  • Classes

  • Objects

  • Arrays

  • Indexers

  • Interfaces

  • Every class is derived from Object — even user-defined classes.

  • Value types and strings also inherit from Object:

  • Strings are immutable: they cannot be changed after they are created. Anything that appears to modify a string actually returns a new string object.


C# Introduction



c sharp logo

Back to Shortcuts

Open Source


Articles


Troubleshooting


Meetups


Stack and Heap


Programming Features Help


Algorithms


Console Games

IOT (Internet of Things)


Open Source


Tools


github logo

Back to Shortcuts

Scope

Control Flow

Arrays and Lists

Strings

DateTime

Enums

Strings

Procedural

OPP

Additional Topics


github logo

Back to Shortcuts

Database Information

Database Notes

Class library takes care of data access in Razor Pages (and other web applications) once

  • Connecting to a database is a two-way process. A user interface should not talk directly to a database.

    • When a application is talking to a database or getting information from a database, there needs to be a Model (directory)
    • A model is a class with a few properties. The model holds data together.
  • Databases (directory) has database/data access code. This where there is direct communication with a database

  • Data (directory) Classes in Data folder will talk to classes int the Databases folder which talks to the SQL database

    • Classes in the Data folder are what the user interface will talk to
    • The user interface may call a Data class, and a method inside the class can figure out the query it needs to get information
      • And then call class in Databases class


c sharp logo

Back to Shortcuts

C# Repl

> #r "C:\Users\yourusername\source\repos\BirdWatcher\BirdWatcher\BirdWatcher.dll" = your project will be linked to C# Interactive (REPL)

Code Snippets

Visual Studio Shortcuts

Control + Shift N = start a new project

Alt UP ARROW / DOWN ARROW = move a single or multiple lines of code up or down

control + j = brings back intellisense

control + h = replace text with

control + x = cut a single line

control + kc = // comment several lines out

control + . = // using System ...

control + k = uncomment several lines out

shift + tab = unindent lines of code

control shift b = complie (build)

control shift d = copy and past previous line

cw + tab tab = Control.WriteLine() (press tab twice)

try tab = try block created (works for if, while, do, for and foreach statements as well)

ctor = Makes a constructor

prop + tab tab = declare auto-properties

propfull + tab tab = declare full on properties

control + tab = get back to another file

type /// private static void addTwoNumbers ... = add /// <summary> comments </summary>

Control R + R = change name of a class

Control + Alt + Click = multiple line selection

Control + Home = Arrive at top of page (without scrolling)

Control + End = Arrive at end of page (without scrolling)

Control . = Recognize a class from another namespace

Control R, A = run test

mvcaction4 + tab = create a ActionResult (MVC)

In case mvcaction4 snippet does not work click here

Debugging

F9 = add break point

F5 = run in debug mode

F10 = step over

Shift + F11 = step out of

Shift + F5 = exit debug mode

Back to Shortcuts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.