C-Family Programming - College Homework Help and Online Tutoring

  1. https://docs.microsoft.com/en-us/dotnet/standard/automatic-memory-management?redirectedfrom=MSDN

It is difficult for a developer to consider writing C# code to any real degree without dipping into the .NET Framework or Mono extensively. As a result, most tutorials and examples you encounter take this coupling for granted and do not really differentiate between the two, and this will be no exception. The following code is for use with .NET 4.6 (the latest version of the framework at the time of writing) but should work on Mono or older versions without too many problems. First let’s turn our attention to the inevitable “Hello World” application. First off we can make a new solution (this code is targeted at Visual Studio, the dominant IDE for C#), selecting the Console Application template. This gives us a single code file, “Program.cs”, and an application config file called App.config, which we will disregard for now. By default, the following code is given to us: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Test { class Program { static void Main(string[] args) { } } } Anyone familiar with writing C console applications will recognize what they are seeing here. The program class is designed to be the startup class for our application (from the project and solution properties) and the Main() method is our entry point. At execution time, code will come in here, execute to the end of Main() function, and then quit. If you run this application by hitting ‘start’, you will see a console window appear and disappear just as quickly, which means our empty application has executed without error. The first thing we can do is add the following line to our application so that when it has completed, the application waits for us to press a key before exiting. We will leave this line at the end of our application for the duration of this tutorial. Add it, and try running your application again. Console.ReadKey(); Now add the following line above this one, to create our ‘Hello World’ application. Console.WriteLine("Hello, World!"); When you run this, you will now see your greeting as text. Let’s examine what’s happening here with both lines of code. Console is a static class provided to us from the System namespace, which we can see at the top of our file (“using System;”). Static classes do not require an instantiated object to execute their functions, and are instead executed solely from any code module that has access to the namespace of your static class. The static methods we are using here are ‘WriteLine’ and ‘ReadKey’, which are fairly self-explanatory. WriteLine is passed one argument, which is our text string, “Hello World!” When we run that line of code, the application prints our text to the console, followed by a new-line. The program then waits (also referred to as ‘blocking for input’) at the ‘Console.ReadKey()’ line until the user pushes a key and the program can continue to the end, exiting. As you can see, these two lines actually perform a large number of low-level operations without us ever having to think about them, which is the strength of high level languages from a programming perspective. Let’s go ahead and customize our input by reading from the console. Above our WriteLine method, we can add another method – ReadLine. ReadLine is like ReadKey, but instead we wait for a user to type several characters and press return, at which point the text they have typed will be returned and we can store it in a variable. This is done with the equals (=) operator. In the following example, we combine variable declaration and assignment into one line after prompting for input. The output of the ReadLine method is subsequently stored in the userName variable which is of type string (as in a sequence of characters, or text). Now, our program looks like this: static void Main(string[] args) { Console.WriteLine("Please enter your name:"); string userName = Console.ReadLine(); Console.WriteLine("Hello, " + userName); Console.ReadKey(); }

However, this program is identical to the following:

static void Main(string[] args) { Console.WriteLine("Please enter your name:"); string userName; userName = Console.ReadLine(); Console.WriteLine("Hello, " + userName); Console.ReadKey(); } This is because declaring a variable and later assigning it is the same as doing both actions on the same line. In fact, the second example is a bad practice, as you may forget to assign your variable to some value before you use it, which will cause your program to crash. The other part of this example that has changed is the ‘WriteLine’ method, which now is outputting "Hello, " + username. In this instance, the + operation usually associated with adding numbers is combining two strings. As a result, when executed, the value inside ‘username’ is appended to the end of “Hello, “ to create a new string. Try running this program now and experimenting with the output. One brief word on variable declarations before we move on: You may see other tutorials and subsequent ones in this series use ‘var’ instead of ‘string’ (or any other type like ‘int’). This is because modern versions of C# can save the programmer the job of declaring a variable type and instead let the compiler do that work. As a result, the compiler has access to information about the ‘Console.ReadLine()’ method and can correctly determine that it will return a string, which it substitutes for ‘var’ at compile time. As a result, this is equally valid, and an even better practice: var userName = Console.ReadLine(); Having built this basic application you have gained a brief insight into input/output methods and the structure of an application. Once you understand such procedural code and basic variables, it is time to move on to understand object oriented programming in order to make the most of the power of a high level language like C#. Since we have tutors in all C-Family Programming related topics, we can provide a range of different services. Our online C-Family Programming tutors will: With these capabilities, our college C-Family Programming tutors will give you the tools you need to gain a comprehensive knowledge of C-Family Programming you can use in future courses. Our tutors are just as dedicated to your success in class as you are, so they are available around the clock to assist you with questions, homework, exam preparation and any C-Family Programming related assignments you need extra help completing. In addition to gaining access to highly qualified tutors, you'll also strengthen your confidence level in the classroom when you work with us. This newfound confidence will allow you to apply your C-Family Programming knowledge in future courses and keep your education progressing smoothly. Because our college C-Family Programming tutors are fully remote, seeking their help is easy. Rather than spend valuable time trying to find a local C-Family Programming tutor you can trust, just call on our tutors whenever you need them without any conflicting schedules getting in the way.

4,368views
4.4
(77 ratings)

Related Study Guides

BIO 102 Unit 8 The Urinary System Assignment (GRADED A+) Questions and answer solutions (100 out of 100) - BIO 102 - Stuvia US

BIO 102 Unit 8 The Urinary System Assignment (GRADED A+) Questions and answer solutions (100 out of 100) Unit 8 The Urinary System Assignment Start Assignment Follow all instructions and guidelines fo...

human-resourcesart-design

Electrical engineering Questions & Answers | Solutioninn.com

1. Design an ammeter with three scales: 0-200 EA, 0-2 mA, and 0-10 mA. Use a current sensor rated at 200 EA, 100 mv. What resistance does the instrument insert in the circuit at each scale? 2. Using.....

art-designstatistics

HIST405N Week 1 | US Culture and History in History - Chamberlain university

HIST405N United States History Week 1 Assignment Required Resources Read/review the following resources for this activity: Textbook: Chapter 1, 2, 3, 4 Lesson Minimum of 1 scholarly source (in additio...

historyart-design

[Solved] What type of web server is sending packet | SolutionInn

Question: What type of web server is sending packet/frame 280 of the capture? 2. What type of HTTP Status Code is the web server in What type of web server is sending packet/frame 280 of the capture?...

statisticsart-design

ENGL147 Week 6 | General English in English - Chamberlain university

ENGL147 Advanced English Composition Week 6 Quiz Question 1Which of the following would be the most helpful reply to a classmates’ draft during peer review? “Sarah, I really liked this essay! You migh...

writingenglish-literature

C-Family Programming - College Homework Help and Online Tutoring

The C family of programming languages are rivaled only by Java in their popularity. In 2014, the C family (that is C, C++ and C#) had a combined market share of 27.3% to Java’s 19.3%[1] Considering th...

computer-sciencestatistics

HIST405N Week 1 | US Culture and History in History - Chamberlain university

HIST405N United States History Week 1 Discussion The Cost of Expansion Required Resources Read/review the following resources for this activity: Textbook: Chapter 3, 4 Lesson Minimum of 1 scholarly so...

historystatistics

HUM370 Week 1 | Archaeology in Anthropology - Westcoast university

HUM370 Cultural Pluralism Week 1 Assignment Culture and Conflict Reflection Essay In this essay, you will reflect on the causes and consequences of prejudice and apply the theories and strategies of c...

writingenglish-literature

Need Help With A Similar Question?

Our experts deliver perfect solutions with guaranteed A+ grades

A+
Student Grade
98%
Success Rate
12h
Delivery Time
Join 1,000+ students who got their perfect solutions
Rated 4.9/5 by satisfied students

Need Help With This Question?

Academic Expert

Subject Matter Specialist

98%
Success Rate
24/7
Support

Why Students Trust Us

  • PhD-Level Expertise
  • Original Work Guarantee
  • Better Grade or Free

"Got an A+ on my assignment. Exactly what I needed!"

Recent Student