.
Download Power BI
|
Go to the download page. |
https://www.microsoft.com/en-us/download/details.aspx?id=58494 |
.
.
Download Power BI
|
Go to the download page. |
https://www.microsoft.com/en-us/download/details.aspx?id=58494 |
.
.
Download the VS2019 downloader program from:
Alternatively, download from:
Run download program with the following parameters:
vs_community__cf159a3372a047a19456d60fe6ad9651__v16.11.exe --layout c:\vs2019c_1611 --lang en-US
where c:\vs2019c_1611 is the target download location for the VS2019 installation files.
After download process is completed, go to the target location and run the following command:
vs_community.exe --noWeb
-------------------------------------------------------------
ADDITIONAL NOTE:
For .NET web and .NET desktop development layout only, run:
vs_community__cf159a3372a047a19456d60fe6ad9651__v16.11.exe --layout c:\vs2019c_1611 --add Microsoft.VisualStudio.Workload.ManagedDesktop --add Microsoft.VisualStudio.Workload.NetWeb --includeOptional --lang en-US
.
.
2) https://www.mycompiler.io/new/csharp
3) programiz.com/csharp-programming/online-compiler/
4) https://www.onlinegdb.com/online_csharp_compiler
6) https://www.jdoodle.com/compile-c-sharp-online/
7) https://dotnet.microsoft.com/en-us/learn/dotnet/in-browser-tutorial/1
8) https://www.programiz.com/csharp-programming/online-compiler/
9) https://replit.com/languages/csharp
10) https://onecompiler.com/csharp
.
Select continue to install.
Wait for the downloading proces.
.
New to Visual Studio? Learning a new development tool can be overwhelming. Take this step-by-step learning journey at your own pace to successfully create a simple app in any language of your choice. Let’s get started!
Install Visual Studio
First please make sure to open your Visual Studio download and install. You can save installation time and disk space by selecting just the components needed. You can always incrementally add more components later at any time as needed.
https://visualstudio.microsoft.com/downloads/
.
Wondering how to learn C#? Then you’ve come to the right place. We will answer all your C# questions, such as: what are the features of C#? Is C# hard to learn? What are the best ways to learn C#? What’s the job market like for C# programmers? And much more. By the end of this article, you will know exactly how to learn C# easily.
What is C#?
C# (pronounced as C Sharp), developed by Microsoft, uses the .NET framework. It’s a multi-purpose programming language that is modern and object-oriented.
C# is more of a blend of C and C++ programming languages. However, in contrast, the syntax of the C# language is expressive, simple, intuitive, and easy to understand.
Complexities introduced by the C++ language are highly simplified by the C# language. This includes enumerations, nullable types, direct memory access, delegates, etc., which are also not found in Java.
C# is ranked as the 7th most popular programming language. While most of the programming languages are created to carry out a specific set of tasks, C# is a general-purpose programming language.
You can use C# to work with databases, create high-speed graphics for video games, play audio/video effects, control connected devices, and more.
C# is interpreted as well as compiled. Unlike C++ and Java, C# provides excellent screen handling support for Web as well as Desktops. This is where C# stands with respect to other popular programming languages.
Photo of C# Insights Graph
Properties of C#
Before we move further ahead, let’s discuss a few properties of the C# programming language that will help you digest its popularity better.
It’s Safe
Data loss is not possible in C# because it does not support type conversion. Moreover, it supports non-nullable and nullable value types as well. As a result, developers can write code safely.
It’s Modern and Intuitive
C# was created with the sole aim that developers can access a general-purpose language that is easy to understand and can compete with other modern languages in terms of carrying out the functionalities.
The C# programming language can develop applications and software for various fields and platforms, including Android, iOS, Web, or Windows.
It’s Open-Source and Free
C# is an open-source language developed by Microsoft; hence it’s free to use. It has a huge base of developers that contribute and are highly active and supportive.
Applications of C#
C# is a middle-level language that makes it user-friendly, intuitive, and easy to understand. Moreover, C# has a faster execution time. That’s why it is used widely for embedded programming as well.
Apart from this, C# programming language is widely used to build large-scale applications for Windows, Desktop and Web applications, Games, Virtual Reality (VR), Database Applications, and other services for the Web. You can also use it to develop iOS and Android applications as well.
Features and Advantages of C#
Photo of C# advantages diagram
Before discussing why you should switch over to C# from C++, Java, or other languages, let’s discuss a few features and advantages that C# brings to the table.
Fast: C# is a fast programming language and has a quick execution time.
Simple: C# doesn’t require you to include header files — it has a structured approach that allows you to break the problem into parts and has a rich set of libraries and data types.
Object-Oriented: It supports OOPS concepts that make maintenance and development easier. It supports all aspects of object-oriented programming such as inheritance, polymorphism, abstraction, encapsulation, interfaces, etc.
Type-Safe: It allows you to write and develop type-safe code, improving security. You will not be able to perform unsafe casts, such as converting a double data type to a boolean. It automatically initializes data types and objects as well as classes to zero or null values.
Interoperability: It can interact well with other programming languages. This helps to increase the reusability of the code and create an efficient program. It can use COM objects irrespective of the language that’s used to write them. It can also call out any API.
Structured: C# divides a large program into modules, procedures, or functions to solve specific problems.
Component-Oriented: C# is a component-oriented programming language, meaning it uses events, properties, attributes, methods, etc., to allow and create self-contained and described components called functionalities.
Platform-Independent: Any platform that has .NET installed on it can run C#.
Automatic Garbage Collection: The system does not get messed up or hanged during execution because C# has an automatic garbage collection that automatically removes dangling items during runtime.
No Memory Leak: It has strong and high memory backup that helps in avoiding memory leakage, unlike C++.
Why Should You Learn C# in 2022?
Let’s discuss a few reasons why you should learn a multi-purpose language like C# in 2022.
It’s simple, easy-to-use, intuitive, and readable.
It’s a strongly typed language that enhances developer productivity and makes common tasks easy to do.
It’s a multi-paradigm, object-oriented programming language that supports programming styles such as generic, imperative, functional, and declarative.
You can create multiple applications such as console applications, desktop applications, applications for native mobile, AI, IoT, and cloud.
C# runs on a well-engineered, robust, solid .NET framework.
It’s platform-independent, modern, mature, and very actively developed and maintained.
It’s open-source, well-documented, and has an active, vibrant community.
It can be used for software development since it has built-in design practices and patterns.
It is very fast to execute and has a rich set of libraries.
.
.
Create VB Console Project |
We will start at the root of ALL OUR PROJECTS c:\ZT\> |
CLI: dotnet new console -lang VB -o vbtest1 |
CLI: cd vbtest1 |
CLI: dotnet build |
CLI: dotnet run |
See Appendix 1 for Screenshot of VB Console Project Based On DotNet Framework |
Online code beautifier tool: |
1) Print Hello World Program (VB) |
Pseudo Code: 1. BEGIN 2. PRINT "Hello World" 3. END |
Imports System Module Program Sub Main(args As String()) Console.WriteLine("Hello World!") End Sub End Module |
2) Sum Numbers Program (VB) |
Pseudo Code: 1. BEGIN 2. PRINT 1 + 2 3. END |
CLUE: Console.WriteLine(1+2); |
Imports System Module Program Sub Main(args As String()) Console.WriteLine(1 + 2) Console.ReadKey() End Sub End Module |
3) Sum Variables Program (VB) |
Pseudo Code: 1. BEGIN 2. INPUT var1, var2 3. PRINT var1+var2 4. END |
CLUE: |
Imports System Module Program Sub Main(args As String())
Dim var1 As Integer = Console.ReadLine()
Dim var2 As Integer = Console.ReadLine()
Console.WriteLine(var1 + var2)
Console.ReadKey()
End Sub End Module |
4) Multiply Variables Program (VB) |
Pseudo Code: 1. BEGIN 2. INPUT var1, var2 3. PRINT var1 * var2 4. END |
Imports System Module Program Sub Main(args As String())
Dim var1 As Integer = Console.ReadLine()
Dim var2 As Integer = Console.ReadLine()
Console.WriteLine(var1 * var2)
Console.ReadKey()
End Sub End Module |
5) Divide Variables Program (VB) |
Pseudo Code: 1. BEGIN 2. INPUT var1, var2 3. IF var2=0 4. THEN PRINT "Error. Division by zero." 5. ELSE PRINT var1/var2 6. END |
CLUE: Try input for 2 rounds. For round1 => var1=4, var2=2 For round2=> var1=2, var2=0 |
Imports System Module Program Sub Main(args As String())
Dim var1 As Double = Console.ReadLine()
Dim var2 As Double = Console.ReadLine()
If var2 = 0 Then
Console.WriteLine("Error. Division by zero") Else
Console.WriteLine(var1 / var2)
End If
Console.ReadKey()
End Sub End Module |
6) Count Numbers Program (VB) |
Pseudo Code: 1. BEGIN 2. PRINT "Start counting." 3. FOR i LOOP := 1 to 3 STEP 1 4. PRINT i 5. END LOOP 6. PRINT "Done." 7. END |
CLUE: Note:loop index number starts with 0. |
Imports System Module Program Sub Main(args As String())
Console.WriteLine("Start Counting.")
For i As Integer = 0 To 2 Step 1
Console.WriteLine(i) Next
Console.WriteLine("Start Done.")
End Sub End Module |
7) Display Array Values Program (VB) |
1. BEGIN 2. INITIALISE ARRAY arr[5] TO CONTAIN VALUES a,b,c,d,e 3. PRINT "Displaying array values." 4. FOR i := 1 to 5 5. PRINT arr[i] 6. END FOR LOOP 7. PRINT "Done." 8. END |
CLUE: Plan your data type for array carefully string[] arr = new string[] {"a", "b", "c", "d", "e"}; string[] arr = {"a", "b", "c", "d", "e"}; |
Imports System Module Program Sub Main(args As String())
Dim arr() As String = {"a", "b", "c", "d", "e"}
Console.WriteLine("Displaying array values.")
For i As Integer = 0 To 4 Step 1
Console.WriteLine(arr(i))
Next
Console.WriteLine("Start Done.")
End Sub End Module |
Imports System Module Program Sub Main(args As String())
Dim arr() As Char = {"a", "b", "c", "d", "e"}
Console.WriteLine("Displaying array values.")
For i As Integer = 0 To 4 Step 1
Console.WriteLine(arr(i))
Next
Console.WriteLine("Start Done.")
End Sub End Module |
8) Edit Array Values Program (VB) |
Pseudo Code: 1. BEGIN 2. INITIALISE ARRAY arr[i] WITH VALUES 1,2,3,4,5 3. FOR i := 1 to 5 4. PRINT arr[i] 5. END FOR LOOP 6. INPUT indexnumber 7. INPUT arrayvalue 8. arr[indexnumber] = arrayvalue 9. FOR i := 1 to 5 10. PRINT arr[i] 11. END FOR LOOP 12. END |
CLUE: Try input 1 and f What is the output? a b c d e Input indexNumber = 1 Input arrayValue = f Let arr[1]=f a f c d e |
Imports System Module Program Sub Main(args As String())
Dim arr() As Char = {"a", "b", "c", "d", "e"}
Console.WriteLine("Displaying array values.") For i As Integer = 0 To 4 Step 1 Console.WriteLine(arr(i)) Next Console.WriteLine("Start Done.")
Console.WriteLine("Enter index number and new value:") Dim indexNumber As Integer = Console.ReadLine() Dim arrayValue As String = Console.ReadLine() arr(indexNumber) = arrayValue
Console.WriteLine("Displaying array values.") For i As Integer = 0 To 4 Step 1 Console.WriteLine(arr(i)) Next Console.WriteLine("Start Done.")
End Sub End Module |
SEBELUM INPUT
arr[0]=a
arr[1]=b
arr[2]=c
arr[3]=d
arr[4]=e
INPUT
indexNumber? Cth 1
arrayValue? Cth f
KEMASKINI NILAI DALAM ARRAY
arr[1]=f
SELEPAS INPUT
arr[0]=a
arr[1]=f
arr[2]=c
arr[3]=d
arr[4]=e
9) Modular Program (VB) |
Pseudo Code: 1. BEGIN displaydata 2. FOR all item in array PRINT item values 3. END displaydata 1. BEGIN updatedata 2. INPUT indexnumber, arrayvalue 3. arr[indexnumber]=arrayvalue 4. CALL displaydata 4. END updatedata 1. BEGIN main 2. CALL displaydata 3. CALL updatedata 4. END main |
CLUE: Main { Dim arr() as Char={"a","b","c","d","e"}; displayData(arr); updateData(arr); displayData(arr); } Sub displayData(ByVal arr() as Char) … End Sub Sub updateData(ByRef arr() as Char){ … End Sub |
Imports System Module Program Sub Main(args As String())
Dim arr() As Char = {"a", "b", "c", "d", "e"} displayData(arr) updateData(arr) displayData(arr)
End Sub Sub displayData(ByVal arr() As Char) Console.WriteLine("Displaying array values.") For i As Integer = 0 To 4 Step 1 Console.WriteLine(arr(i)) Next Console.WriteLine("Start Done.") End Sub Sub updateData (ByRef arr() As Char) Console.WriteLine("Enter index number and new value:") Dim indexNumber As Integer = Console.ReadLine() Dim arrayValue As Char = Console.ReadLine() arr(indexNumber) = arrayValue End Sub End Module |
cd /
cd ZT
cd cstest1
10) Program Parameter (VB) |
Imports System Module Program Sub Main(args As String())
Console.WriteLine(args(0))
End Sub End Module |
Type console command: |
dotnet run hello |
Output: |
TRY CATCH BLOCK (VB) |
Try ‘Try to do something here Catch e As Exception Console.WriteLine(e.Message) End Try |
11) Working With Text File (VB) |
Get back to root of projects C:\ZT> Type command: dotnet new console -lang vb -o vbtrycatch Type command: cd vbtrycatch |
In the VC project explorer panel, find the vbtrycatch folder. You will see Program.vb Create a text file data.txt in the project root folder (i.e. vbtrycatch folder). Type following text into the file (i.e. data.txt): this is a test |
Edit Program.vb by replacing the existing codes with the following codes. |
Imports System Imports System.IO Module Program Sub Main() Dim fileName As String = "data.txt" Try Using writer As StreamReader = New StreamReader(fileName) Dim line As String line = sr.ReadLine() While ( line <> Nothing) Console.WriteLine(line) line = sr.ReadLine() End While End Using Catch e As Exception Console.WriteLine(e.Message) End Try Console.ReadKey() End Sub End Module |
C:\ZT\vbtrycatch>dotnet run This is a test |
Try changing the content of data.txt (e.g. this is another test). Run again your program. Check that new data is displayed. |
C:\ZT\vbycatch>dotnet run This is a another test |
Sending And Receiving Data Through Internet HyperText Transfer Protocol |
Suppose that we want to send data to a target server at the URL https://httpbin.org/post |
For illustration purposes, we will use the REST demo application at https://resttesttest.com as a form tool for data submission to the target server. The target server URL is specifically allocated for the POST method. Sending a FORM method will result with HTTP 200 success code. |
On the other hand, sending a GET method will result in an HTTP 400 error code. |
In the next part, we are going to write a DotNet Console application to work similar to the RestTestTest web site. |
12) Working With Web Request (VB) |
Imports System Imports System.text Imports System.Web Imports System.Net Imports System.IO Module Program Sub Main() Try Dim postdata As String = "comments=good&custemail=harry@porter.com&custname=harry+porter&custtel=0123456789&delivery=jnt" WebrequestWithPost("https://httpbin.org/post",Encoding.UTF8,postdata,"application/x-www-form-urlencoded") Catch e As Exception Console.WriteLine(e.Message) End Try Console.ReadKey() End Sub Function WebrequestWithPost(ByVal url As String, ByVal dataEncoding As Encoding, ByVal dataToPost As String, ByVal contentType As String) As String Dim postDataAsByteArray As Byte() = dataEncoding.GetBytes(dataToPost) Dim returnValue As String = String.Empty Try Dim webRequest As HttpWebRequest = WebRequest.CreateHttp(url) 'change to: dim webRequest as var = DirectCast(WebRequest.Create(url), HttpWebRequest) if you are your .NET Version is lower than 4.5 If (Not (webRequest) Is Nothing) Then webRequest.AllowAutoRedirect = False webRequest.Method = "POST" webRequest.ContentType = contentType webRequest.ContentLength = postDataAsByteArray.Length Dim requestDataStream As Stream = webRequest.GetRequestStream requestDataStream.Write(postDataAsByteArray, 0, postDataAsByteArray.Length) requestDataStream.Close Dim response As Webresponse = webRequest.GetResponse Dim responseDataStream As Stream = response.GetResponseStream If (Not (responseDataStream) Is Nothing) Then Dim responseDataStreamReader As StreamReader = New StreamReader(responseDataStream) returnValue = responseDataStreamReader.ReadToEnd Console.WriteLine(returnValue) responseDataStreamReader.Close responseDataStream.Close End If response.Close requestDataStream.Close End If Catch ex As WebException If (ex.Status = WebExceptionStatus.ProtocolError) Then Dim response As HttpWebResponse = CType(ex.Response,HttpWebResponse) 'handle this your own way. Console.WriteLine("Webexception! Statuscode: {0}, Description: {1}", CType(response.StatusCode,Integer), response.StatusDescription) End If Catch ex As Exception 'handle this your own way, something serious happened here. Console.WriteLine(ex.Message) End Try Return returnValue End Function End Module |
https://codesnippets.fesslersoft.de/send-data-using-a-webrequest/ |
13) SQL Server Connection (VB) |
CLI: dotnet new console -lang c# -o vbdbcon1 |
CLI: dotnet add package Microsoft.Data.SqlClient --version 5.0.0 |
Imports System Imports Microsoft.Data.SqlClient Module Program Sub Main(args As String()) Try
Dim builder As New Microsoft.Data.SqlClient.SqlConnectionStringBuilder()
builder.DataSource = "smacomdb.mssql.somee.com" builder.UserID = "smarcompu_SQLLogin_1" builder.Password = "" builder.InitialCatalog = "smacomdb" builder.TrustServerCertificate = True
Using connection As New SqlConnection(builder.ConnectionString)
Console.WriteLine(vbCrLf & "Query data example:") Console.WriteLine("=========================================" & vbCrLf)
connection.Open()
Dim sql As String = "SELECT name, collation_name FROM sys.databases"
Using command As New SqlCommand(sql,connection)
Using reader As SqlDataReader = command.ExecuteReader() If reader.HasRows Then Do Whilereader.Read 'Console.WriteLine("{0}", reader.GetString(0)) Console.WriteLine($"{reader.GetString(0)}") Loop End If End Using End Using connection.Close() End Using Catch ex As Exception End Try Console.WriteLine(vbCrLf & "Done. Press enter.") Console.ReadLine() End Sub End Module |
CLI: cd vbdbcon1 CLI: dotnet build CLI: dotnet run |
.