第一个程序依然是经典的Hello world.开始学习C# 感觉还不错
  

Hello World
 1
using System;
 2
// 我的第一个程序 HelloWorld
 3
namespace HelloWorld
 4

{
 5
    class Hello
 6
    
{
 7
        static void Main()
 8
        
{
 9
            System.Console.WriteLine("Hello World!");
10
        }
11
        //static int Main()
12
        //{
13
        //    System.Console.WriteLine("Hello World!");
14
        //    return 0;
15
        //}
16
        //static void Main(string[] args)
17
        //{
18
        //    if (args != null)
19
        //    {
20
        //        System.Console.WriteLine(args[0].ToString());
21
        //    }
22
        //}
23
        //static int Main(string[] args)
24
        //{
25
        //    if (args != null)
26
        //    {
27
        //        System.Console.WriteLine(args[0].ToString());
28
        //    }
29
        //    return 0;
30
        //}
31
   }
32
} 
 经典的 Hello World
1.C#是有命名空间这个概念的,
简单的说就是一伙有相同爱好的人的住在一起,给他们的房子起的名字.你找到了房子,自然就可以找到他们.
2.//是代表注释的,而且 /* */ 也可以代表注释
3.注释掉的Main 方法都是可以的.区别就是传参不传参,有返回值,没有返回值的区别
4.类和命名空间的第一个字母是大写的.
5.System.Console.Writeline:是属于System 这个房子的.意思是输出一行. 因为using System.所以这里也可以直接写成Console.WriteLine();
6.using System;  using 代表的引用.
7.编译这个 则在编译器中输入 csc Hello.cs 

Main函数
1
class TestClass
2

{
3
    static void Main(string[] args)
4
    
{
5
      System.Console.WriteLine(args.Length);
6
    }
7
}
8
9
 
Main 方法是程序的入口点.一个 C# 程序中只能有一个入口点
Main 方法的参数是表示命令行参数的 String 数组。通常通过测试 Length 属性来检查参数是否存在
if (args.Length == 0)
{
    System.Console.WriteLine("请输入参数.");
    return 1;
}
Convert 和 Parse 方法可以将字符串参数转换为数值类型,但是这种转换是有危险的,例如
args[0]='aa';
Convert.ToInt64(args[0]);
Int64.Parse(args[0]);
这样的转换都是无意义的,而且会抛出异常.在程序中出现异常是很可怕的.....
我们可以自己写一个

自己的ToInt
 1
 ToInt 转换成整型 不抛例外#region ToInt 转换成整型 不抛例外
 2
        /**//// <summary>
 3
        /// 转换成整型 不抛例外
 4
        /// </summary>
 5
        /// <param name="objInt"></param>
 6
        /// <param name="defaultValue"></param>
 7
        /// <returns></returns>
 8
        public int ToInt(object objInt, int defaultValue)
 9
        
{
10
            try
11
            
{
12
                if (objInt == null || objInt is System.DBNull)
13
                
{
14
                    return defaultValue;
15
                }
16
                else
17
                
{
18
                    try
19
                    
{
20
                        return Convert.ToInt32(objInt);
21
//return Int32.Parse(objInt);
22
                    }
23
                    catch
24
                    
{
25
                        return defaultValue;
26
                    }
27
                }
28
            }
29
            catch
30
            
{
31
                return defaultValue;
32
            }
33
        } 
Int32.Parse 和Convert.ToInt32都是可以的. 通过Try catch 有效的规避了异常..