Text in C# defines types for character encoding and string manipulation
Search This Blog
Thursday, November 7, 2013
Regex IsMatch method
C# > Text > RegularExpressions > IsMatch
Regex IsMatch method indicates whether the regular expression specified finds a match in a specified input string.
Example:
foreach (string partNumber in partNumbers)
if (rgx.IsMatch(partNumber))
MessageBox.Show (partNumber);
Pattern
^ begin the match at the beginning of the line.
[a-zA-Z0-9] match a single alphabetic character (a through z or A through Z) or numeric character. - match a hyphen
* must be zero or more of these characters
$ end the match at the end of the line
Regex IsMatch method indicates whether the regular expression specified finds a match in a specified input string.
Example:
string[] partNumbers = { "1298-6736","343434" };
Regex rgx = new Regex(@"^[a-zA-Z0-9-]*-[a-zA-Z0-9]*$");foreach (string partNumber in partNumbers)
if (rgx.IsMatch(partNumber))
MessageBox.Show (partNumber);
Pattern
^ begin the match at the beginning of the line.
[a-zA-Z0-9] match a single alphabetic character (a through z or A through Z) or numeric character. - match a hyphen
* must be zero or more of these characters
$ end the match at the end of the line
Etichete:
c#
Convert color to html color C#
C# > Color
ColorTranslator.ToHtml translates the specified Color structure to an HTML string color.
Example:
ColorTranslator.ToHtml translates the specified Color structure to an HTML string color.
Example:
Color cl = Color.FromArgb(0, 99, 148);
string htmlColor = ColorTranslator.ToHtml(cl);
Etichete:
c#
Get Oracle Version
Oracle > Version
V$VERSION displays version numbers of core library components in the Oracle Database.
Example:
select * from v$version
Result:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
V$VERSION displays version numbers of core library components in the Oracle Database.
Example:
select * from v$version
Result:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
Etichete:
Oracle/PLSQL
Sealed modifier C#
C# > Modifiers > sealed
Sealed modifier prevents other classes from inheriting from it.
Also you can use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Examples
1. Sealed class
class C1 { }
sealed class C2 : C1 { }
class C3 : C2 { } // Error : cannot derive from sealed type C2
2. Sealed method
protected virtual void F() { }
protected virtual void F1() { }
}
class B : A
{
sealed protected override void F() { }
protected override void F1() { }
}
class C : B
{
protected override void F() { } //Error cannot override inherited member because it is sealeD
protected override void F1() { }
}
Sealed modifier prevents other classes from inheriting from it.
Also you can use the sealed modifier on a method or property that overrides a virtual method or property in a base class. This enables you to allow classes to derive from your class and prevent them from overriding specific virtual methods or properties.
Examples
1. Sealed class
class C1 { }
sealed class C2 : C1 { }
class C3 : C2 { } // Error : cannot derive from sealed type C2
2. Sealed method
class A
{protected virtual void F() { }
protected virtual void F1() { }
}
class B : A
{
sealed protected override void F() { }
protected override void F1() { }
}
class C : B
{
protected override void F() { } //Error cannot override inherited member because it is sealeD
protected override void F1() { }
}
Etichete:
c#
const c#
C# > Modifiers > const
The const specifies that the value of the field or the local variable is constant and it cannot be modified.
The const keyword differs from the readonly keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor.
Example:
class SampleConst
{
public int x;
public int y;
public const int c1 = 1;
public const int c2 = c1 + 5;
x = v1 + c1;
y = x + c2;
}
}
The const specifies that the value of the field or the local variable is constant and it cannot be modified.
The const keyword differs from the readonly keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor.
Example:
class SampleConst
{
public int x;
public int y;
public const int c1 = 1;
public const int c2 = c1 + 5;
public SampleConst(int v1)
{x = v1 + c1;
y = x + c2;
}
}
Etichete:
c#
Wednesday, November 6, 2013
sbyte keyword C#
C# > Types > sbyte
The sbyte keyword is an integral type.
Range: -128 to 127
Size: Signed 8-bit integer
Example:
The sbyte keyword is an integral type.
Range: -128 to 127
Size: Signed 8-bit integer
Example:
sbyte k = 127; // ok
k = 128; // Error 1 Constant value '128' cannot be converted to a 'sbyte'
Etichete:
c#
Subscribe to:
Posts (Atom)