Search This Blog

Thursday, October 16, 2014

String IsNullOrEmpty C# Example

C# > String > Methods > IsNullOrEmpty

With this method you can test simultaneously test whether a String is null or its value is Empty.

Example


string s = "test";
bool b = String.IsNullOrEmpty(s); // false
           
s = null;
b = String.IsNullOrEmpty(s); // true
           
s = "";
b = String.IsNullOrEmpty(s); // true

s = " ";

b = String.IsNullOrEmpty(s); // false








Wednesday, October 15, 2014

CONVERT SQL Server Example

SQL Server > Built-in Functions > CONVERT

CONVERT converts an expression of one data type to another.
Example

select CONVERT(nvarchar(30), GETDATE(), 100)

result
Oct 15 2014  9:54AM

Other examples:






Where keyword generic generic type constraint example C#

C# > Generics > where - generic type constraint

With where keyword you can apply restrictions to the kinds of types that client code can use for type arguments when it instantiates the generics class.


Example


    public class A
    {
    }
    public class B:A
    {
    }
    public class GenericList <T> where T : A
    {
    }

    GenericList<A> lst1 = new GenericList<A>(); // OK
    GenericList<B> lst2 = new GenericList<B>(); // OK B derives from A
    GenericList<int> lst3 = new GenericList<int>(); //Error  1      The type 'int' cannot be used as type parameter 'T' in the generic type or method 'WindowsFormsApplication1.GenericList'. There is no boxing conversion from 'int' to 'WindowsFormsApplication1.A'.
       






Tuesday, October 14, 2014

Ushort Type C# Example

C# > Types > ushort

The ushort keyword is an integral type.
Range: 0 to 63535


Example:

byte k = 63535; // ok
k = 63536;      // Error   




Byte Type C# Example

C# > Types > byte

The byte keyword is an integral type.
Range: 0 to 255


Example:

byte k = 255; // ok
k = 256;      // Error   




Wednesday, October 8, 2014

APP_NAME SQL Server Example

SQL Server > Built-in FunctionsAPP_NAME

APP_NAME returns the application name for the current session.

Example:

select APP_NAME();
Result:
Microsoft SQL Server Data Tools, T-SQL Editor



Create form in runtime C#

C# > Windows > Form

A Form is a representation of any window displayed in your application.

Properties
Example

Create form in runtime

Form form1 = new Form();
Button button1 = new Button();
button1.Text = "OK";
button1.Location = new Point(5, 5);
form1.Text = "My Form";
form1.FormBorderStyle = FormBorderStyle.FixedDialog;
form1.MaximizeBox = false;
form1.MinimizeBox = false;
form1.StartPosition = FormStartPosition.CenterScreen;
form1.Controls.Add(button1);

form1.ShowDialog();