A Simple C Program: Printing a Line of Text

C uses some notations that may appear strange to people who have not programmed computers.
I begin by considering a simple C program. First example prints a line of text. The program and its screen output are shown

1 // Fig. 2.1: fig02_01.c
2 // A first program in C.
3 #include <stdio.h>
4
5 // function main begins program execution
6 int main( void )
7 {
8 printf( "Welcome to Programming World!\n" );
9 } // end function main

OutPut

Welcome to Programming World!

Comments
Even though this program is simple, it illustrates several important features of the C language. Lines 1 and 2

#include Preprocessor Directive Line 3 is a directive to the C preprocessor. Lines beginning with # are processed by the preprocessor before compilation. Line 3 tells the preprocessor to include the contents of the standard input/output header () in the program.

Computers Data, Control of sequences and Softwares

C is a concise yet powerful computer programming language that’s appropriate for technically oriented people with little or no programming experience and for experienced programmers to use in building substantial software systems.

you give the command to compile the program. The compiler translates the
C program into machine language-code (also referred to as object code). In a C system, preprocessor program executes automatically before the compiler’s translation phase begins.The C preprocessor obeys special commands called preprocessor directives, which indicate that certain manipulations are to be performed on the program before compilation. These manipulations usually consist of including other files in the file to be compiled and performing various text replacements.

Preprocessor

The instructions you write to command computers to perform actions and make decisions which controls computers (often referred to as hardware). Some examples of Computer Systems i.e

Loader puts program in memory.
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes

Electronic health
These might include a patient’s medical history, prescriptions, immunizations,
lab results, allergies, insurance information and more. Making
this information available to health care providers across a secure network
improves patient care, reduces the probability of error and
increases overall efficiency of the health care system.

Human Genome
The Human Genome Project was founded to identify and analyze the
20,000+ genes in human DNA. The project used computer programs
to analyze complex genetic data, determine the sequences of the billions
of chemical base pairs that make up human DNA and store the
information in databases which have been made available over the
Internet to researchers in many fields.

A billion general-purpose computers, and billions more embedded
computers are used in cell phones, smartphones, tablet computers, home appliances,
automobiles and more. Computers can perform computations and make logical decisions phenomenally faster than human beings can. Many of today’s personal computers can perform billions of calculations in one second.

Computers process data under the control of sequences of instructions called computer programs. These programs guide the computer through ordered actions specified by people called computer programmers. The programs that run on a computer are referred to as software.

How to Quit C#/CSharp application by using a line of code?

Line of Code to quit C# application

I have a few questions about C#:

You can use this method to quit. This is public static function. No need to declare any object. You just need Class name reference.

public static void Exit()

Application.Exit()

or

if(!CApplication.Run())
Enviroment.Exit(1);

Example

public static void Main(string[] args) {
    // Starts the application.
    Application.Run(new Form1());
 }

 private void button1_Click(object sender, System.EventArgs e) {
    // Populates a list box with three numbers.
    int i = 3;
    for(int j=1; j<=i; j++) {
       listBox1.Items.Add(j);
    }

    /* Determines whether the user wants to exit the application.
     * If not, adds another number to the list box. */
    while (MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo) == 
       DialogResult.No) {
       // Increments the counter ands add the number to the list box.
       i++;
       listBox1.Items.Add(i);
    }

    // The user wants to exit the application. Close everything down.
    Application.Exit();
 }

you can also do this.

if (System.Windows.Forms.Application.MessageLoop) 
{
    // WinForms app
    System.Windows.Forms.Application.Exit();
}
else
{
    // Console app
    System.Environment.Exit(1);
}

Response.Redirect() vs Server.Transfer()

Response.Redirect() should be used when:

  • we want to redirect the request to some plain HTML pages on our server or to some other web server
  • we don’t care about causing additional round trips to the server on each request
  • we do not need to preserve Query String and Form Variables from the original request
  • we want our users to be able to see the new redirected URL where he is redirected in his browser (and be able to bookmark it if its necessary)

Server.Transfer() should be used when:

  • we want to transfer current page request to another .aspx page on the same server
  • we want to preserve server resources and avoid the unnecessary roundtrips to the server
  • we want to preserve Query String and Form Variables (optionally)
  • we don’t need to show the real URL where we redirected the request in the users Web Browser

enter image description here

Application, Session, Request, Response and HttpCookie

Application: 

All assignment shows outstanding deals.

System.Web.HttpContext.Current.Application[“Name”] = “Value”;
System.Web.HttpContext.Current.Application[“AppDB”] = “Remote USA”;

Session and Request:

Session[“RequestURL”] = Request.Url.ToString();

Response and HttpCookie:

A cookie is a small bit of text that accompanies requests and pages as they go between the Web server and browser. The cookie contains information the Web application can read whenever the user visits the site.

HttpCookie cookie = new HttpCookie(“Cookie”);
cookie.Value = “Hello Cookie! CreatedOn: ” + DateTime.Now.ToShortTimeString();
//this.ControllerContext.HttpContext.Response
this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
if(this.ControllerContext.HttpContext.Request.Cookies.AllKeys.Contains(“Cookie”))
{
HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies[“Cookie”];
cookie.Expires = DateTime.Now.AddDays(-1);
//this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
this.ControllerContext.HttpContext.Response.Cookies.Remove(“Cookie”);
}

Web Programming Using the Razor Syntax (C#)

The programming using the  razor syntax shows outstanding deals.

The @ character starts inline expressions, single statement blocks, and multi-statement blocks:

Sample Code for:

@: [some text]

<text>some text</text>

@{
    var greeting = "Welcome to our site!";
    var weekDay = DateTime.Now.DayOfWeek;
    var greetingMessage = greeting + " Today is: " + weekDay;
}
<p>Today's weather: @weatherMessage</p>
<!-- Embedding a backslash in a string -->
@{ var myFilePath = @"C:\MyFolder\"; }
<p>The path is: @myFilePath</p>
@if(IsPost) {
    // This line has all content between matched <p> tags.
    <p>Hello, the time is @DateTime.Now and this page is a postback!</p>
} else {
    // All content between matched tags, followed by server code.
    <p>Hello <em>stranger</em>, today is: <br /> </p>  @DateTime.Now
}
@{
    @* This is a comment. *@
    var theVar = 17;
}