C# NotesBasic C# Examples from w3schoolsCreate a StringString 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# PageIn 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 StructureSee 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 valuesSee 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 valueSee: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/methods Page_Load EventPut 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> Set a String and Output it to a Web Page with C#String SampleText = "My sample text"; Write to a Web PageUse a Literal ControlEncapsulationMakes sure "sensitive" data is hidden from users. Private VariableCan only be accessed within the same class. Other classes have no access to it. Get and Set Methods of a PropertySee 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 FrameworkEntity 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 ModifiersC# 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 ClassesA 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(); ClassA class may contain multiple attributes and multiple methods. Main MethodThe main method is the entry point of execution for each class. EventAn 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 NamespaceA 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 EnvironmentVisual Studio Community Edition is a good free tool for C# development, available from the Visual Studio website. C# Programming Guide from MicrosoftCreating a Console App with C#Try Catch Block and Exception HandlingIf 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
|
|
All Content ©2020 WebRef.eu |