ylbtech-C#-片段-插入片段:Visual C#
1.返回顶部

·#if

#if true

#endif

·#region

#region MyRegion

#endregion

·

2.返回顶部

·namespace

namespace MyNamespace
{

}

·class

class MyClass
{

}

·interface

interface IInterface
{

}

·struct

struct MyStruct
{

}

·ator

public Class1()
{

}

· sim

static int Main( string[] args )
{

    return 0;
}

·svm

static void Main( string[] args )
{

}

·index

public object this[int index]
{
    get { /* return the specified index here */ }
    set { /* set the specified index to value here */ }
}

·iterindex

public MyViewIterator MyView
{
    get
    {
        return new MyViewIterator( this );
    }
}

public class MyViewIterator
{
    readonly MyViewIterator outer;

    internal MyViewIterator( MyViewIterator outer )
    {
        this.outer = outer;
    }

    // TODO: provide an appropriate implementation here
    public int Length { get { return 1; } }

    public ElementType this[int index]
    {
        get
        {
            //
            // TODO: implement indexer here
            //
            // you have full access to MyViewIterator privates
            //

            throw new NotImplementedException();
            return default( ElementType );
        }
    }

    public System.Collections.Generic.IEnumerator<ElementType> GetEnumerator()
    {
        for( int i = 0; i < this.Length; i++ )
        {
            yield return this[i];
        }
    }
}

·iterator

public System.Collections.Generic.IEnumerator<ElementType> GetEnumerator()
{

    throw new NotImplementedException();
    yield return default( ElementType );
}

··enum

enum MyEnum
{

}

·attibute

[System.AttributeUsage( AttributeTargets.All, Inherited = false, AllowMultiple = true )]
sealed class MyAttribute : Attribute
{
    // See the attribute guidelines at
    //  http://go.microsoft.com/fwlink/?LinkId=85236
    readonly string positionalString;

    // This is a positional argument
    public MyAttribute( string positionalString )
    {
        this.positionalString = positionalString;

        // TODO: Implement code here

        throw new NotImplementedException();
    }

    public string PositionalString
    {
        get { return positionalString; }
    }

    // This is a named argument
    public int NamedInt { get; set; }
}

·equals

// override object.Equals
public override bool Equals( object obj )
{
    //
    // See the full list of guidelines at
    //   http://go.microsoft.com/fwlink/?LinkID=85237
    // and also the guidance for operator== at
    //   http://go.microsoft.com/fwlink/?LinkId=85238
    //

    if( obj == null || GetType() != obj.GetType() )
    {
        return false;
    }

    // TODO: write your implementation of Equals() here
    throw new NotImplementedException();
    return base.Equals( obj );
}

// override object.GetHashCode
public override int GetHashCode()
{
    // TODO: write your implementation of GetHashCode() here
    throw new NotImplementedException();
    return base.GetHashCode();
}

·using

using(resource)
{

}

·

3.返回顶部

·if

if (true)
{

}

·else

else
{

}

·while

while (true)
{

}

·do

do
{

} while (true);

··switch

switch (switch_on)
{
    default:
}

·for

for (int i = 0; i<length; i++)
{

}

·forr

for (int i = length - 1; i >= 0 ; i--)
{

}

·foreach

foreach (var item in collection)
{

}

·

4.返回顶部

·try

try
{

}
catch (global::System.Exception)
{

throw;
}

·tryf

try
{

}
finally
{

}

·exception

[Serializable]
public class MyException : Exception
{
    public MyException() { }
    public MyException( string message ) : base( message ) { }
    public MyException( string message, Exception inner ) : base( message, inner ) { }
    protected MyException(
      System.Runtime.Serialization.SerializationInfo info,
      System.Runtime.Serialization.StreamingContext context ) : base( info, context ) { }
}

·

5.返回顶部
·unsafe
unsafe
{

}
·checked
checked
{

}
·unchecked
unchecked
{

}
·lock
lock (this)

{

}
··invoke
EventHandler temp = MyEvent;
if (temp != null)
{
    temp();
}

·

·~

~Class1()
{

}
·

6.返回顶部

·prop

public int MyProperty { get; set; }

·propfull

private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
}

·propg

public int MyProperty { get; private set; }

·
··
·cw

Console.WriteLine();

·mbox

System.Windows.Forms.MessageBox.Show("Test");

·

作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
12-29 22:03