Csharp+asp.net Series Tutorials (i)

Source: Internet
Author: User
Tags inheritance integer readline
Asp.net| Tutorial This tutorial is written in C # and ASP.net programming tutorials, what are the deficiencies please point out, or the ideal blog message in the old cat.
First of all explain C #, here is a rough explanation, please purchase the relevant books, or refer to the relevant documents. C # has canceled pointers in C + +, and the number of operators used in C + + (::->) is no longer present, and C # supports a ".". C # has all the features of an object-oriented programming language, such as encapsulation, inheritance, polymorphism, and so on. And more object-oriented than Java, each type can be considered an object. But C # means to allow single inheritance, that is, a class will not have more than one base class. In addition, C # has no global functions, no global variables, and no global constants. Everything must be encapsulated in a class.
Here's a small example of a console application:

Using System;
Class Mikecat
{
public static void Main ()
{
Console.WriteLine ("Mike old cat C # asp.net Introductory series Tutorial-Welcome to visit the ideal of the Old cat");
}
}

In C # The program always starts with the main () method, and the main () method must and can only be included in a class, and the main () method returns a type of void (no return value) or int (returns an integer representing the application error level).
The above using System; used to import a namespace (Namespace) to indicate the hierarchical relationship of a class. If you do not use a using-import namespace, you must precede the class name with the name space each time a class is used.
The input and output of the C # program is implemented through the console. The console is a class under the system name space. Output a string on the screen with Console.WriteLine (), accept the input device input using the Console.ReadLine () method.
Program code:
Class Mikecat
{
public static void Main ()
{
System.Console.WriteLine ("Mike old cat C # asp.net Introductory series Tutorials-Welcome to the ideal of the Old cat");
System.Console.WriteLine ("Please enter user name:");
String User=system.console.readline ();
System.Console.WriteLine ("Welcome: {0} 's coming!", user);
}
}
The first argument in the parameter table of the WriteLine () method, followed by the string, replaces {0}.
If you want to pass command-line arguments to the application when you execute the program, the main () method should be in the format:
Using System;
public class Mikecat
{
public static void Main (string[] args)
{
Console.WriteLine ("Total {0} command-line arguments", args.) Length);
for (int I=0;i<args. length;i++)
{
Console.WriteLine ("Arg[{0}]=[{1}]", I,args[i]);
}
}
}
Single-line annotations in C # with//, multi-line annotations with/*...*/
Using Constants in C #:
Using System
Class Mikecat
{
Public const double pi=3.14;
public static void Main ()
{
Console.WriteLine ("Pi Pi value is {0}", pi);
}
}
A struct type (struct) is a composite data type that organizes some of the related data into a new data type.
Using System;
struct MIKECAT
{
public string Mike;//user
Public UINT Age;//age
public string Email;//email
}
Class Mf
{
public static void Main ()
{
Mikecat zl;//declaring struct type variable ZL
Zl. Name= "Mike Old cat";
Zl. age=24;
Zl. Email= "mike@hebut.com";
Console.WriteLine ("Name: {0}, Age: {1}, mailbox: {2}", ZL. Name,zl. Age,zl. Email);
}
}
The enumeration type (enum) in C # is a set of logically inseparable integer values:
Using System;
Enum Weekday
{
Sunday,monday,tuesday,wednesday,thursday,friday,saturday
};//, look at the semicolon here.
Class Mikecat
{
static void Main ()
{
Weekday day;//declare enum variable day
Day=weekday.tuesday;
Console.WriteLine ("Day's value is {0}", day);
}
}
Each element type in the enumeration type in C # is an int byte long, and the first element value is 0, followed by a 1 increment. You can also assign values directly to an element in an enumeration, followed by increments.
Enum Weekday:byte
{
Sunday=1,monday,tuesday,wednesday,thursday,friday,saturday
};


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.