WebRef.eu  - Internet Marketing and Online Business Resources  

Home / Site Map | Contact

 

C# Notes

Basic C# Examples from w3schools

Create a String

String MyNewString = "My new string text";

Concatenation Operator

Is +

e.g.

String MyNewString = "My new string text" + " with more added" + " and even more added";

Add Page Load Event to C# Page

In Visual Studio, go to Design view, and double click on the page background. This will add:

protected void Page_Load(object sender, EventArgs e)
{

}

to your page.

Method Structure

See https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods

Any method parameters are enclosed in parentheses and separated by commas.

When calling code calls the method, it provides concrete values called arguments for each parameter. 

By default, when a value type is passed to a method, a copy is passed instead of the object itself. Therefore, changes to the argument have no effect on the original copy in the calling method. You can pass a value-type by reference by using the ref keyword. 

Method Return values

See https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods

If the return type, the type listed before the method name, is not void, the method can return the value by using the return keyword.

The return keyword also stops the execution of the method. If the return type is void, a return statement without a value is still useful to stop the execution of the method. Without the return keyword, the method will stop executing when it reaches the end of the code block. 

Passing by reference vs. passing by value

See:

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/passing-value-type-parameters

Page_Load Event

Put the code you want to run on page load into a Page_Load event within script tags at the top of the page before any HTML:

<%@ Page Language="C#" %>

<script runat="server">

   protected void Page_Load(object sender, EventArgs e)
   {
      // Place page-specific code here.
   }

</script>

Set a String and Output it to a Web Page with C#

String SampleText = "My sample text";

Write to a Web Page

See HttpResponse.Write Method

StackOverflow question

Use a Literal Control

See Literal Control script.

Encapsulation

Makes sure "sensitive" data is hidden from users.

Private Variable

Can only be accessed within the same class. Other classes have no access to it.

Get and Set Methods of a Property

See https://www.w3schools.com/cs/cs_properties.asp

Connect to MySQL with C#

MySQL Connector/NET Developer Guide

Language-Integrated Query (LINQ)

LINQ is a technology that integrates query capabilities directly into the C# language. LINQ can be used to connect to MySQL. Microsoft page on LINQ.

Entity Framework

Entity Framework - Is an object relational mapper that lets you work with databases using .NET objects.

Getting Started with Entity Framework Core - A lightweight, extensible, open source and cross-platform version of the popular Entity Framework data access technology.

Access Modifiers

C# protected void:

void is the return type of the method and means it doesn't return anything.

protected means access is limited to the containing class or types derived from the containing class.

static means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class.

Static Classes

static class is basically the same as a non-static class, but there is one difference: a static class cannot be instantiated. In other words, you cannot use the new keyword to create a variable of the class type. Because there is no instance variable, you access the members of a static class by using the class name itself. For example, if you have a static class that is named UtilityClass that has a public static method named MethodA, you call the method by:

UtilityClass.MethodA();

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members

Class

A class may contain multiple attributes and multiple methods.

Main Method

The main method is the entry point of execution for each class.

Event

An event is a message sent by an object to signal the occurrence of an action. The action can be caused by user interaction, such as a button click, or it can result from some other program logic, such as changing a property’s value. More

Namespace

A namespace is a collection of multiple classes. Each namespace must be declared using the keyword 'using'.

The System namespace defines the fundamental classes and events used in C#.

Development Environment

Visual Studio Community Edition is a good free tool for C# development, available from the Visual Studio website.

C# Programming Guide from Microsoft

Creating a Console App with C#

Try Catch Block and Exception Handling

If there is an error in the program, an exception is thrown by the CLR or program code.

 

 



Visit LowPrices.co.uk for Your UK Shopping



 




Low Prices UK Shopping

Compare Prices
at LowPrices.co.uk


Home / Site Map | Contact

All Content ©2020 WebRef.eu