Create a String
String MyNewString = "My new string text";
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.
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
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
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#" %>
Set a String and Output it to a Web Page with C#
String SampleText = "My sample text";
Write to a Web Page
Use a Literal Control
Makes sure "sensitive" data is hidden from users.
Can only be accessed within the same class. Other classes have no access to it.
Get and Set Methods of a Property
Connect to MySQL with C#
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 - Is an object relational mapper that lets you work with databases using .NET objects.
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.
A 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:
A class may contain multiple attributes and multiple methods.
The main method is the entry point of execution for each class.
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
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#.
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.
All Content ©2020 WebRef.eu