Search This Blog

Tuesday, May 20, 2014

XElement C# Example

C# > LINQ > LINQ TO XML > XElement

XElement is an XML element.
With XElement you can create, change, delete elements.

Example


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;






namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            XElement coTree = new XElement("Company",
                new XElement("Dept", 1),
                new XElement("Dept", 2),
                new XElement("Dept", 3));

            XElement co1Tree = new XElement("Company1",
                new XElement("CEO", 1),
                new XElement("Manager", 2),
                from el in coTree.Elements()
                    where (int)el < 3 
                        select el);
            textBox1.Text = co1Tree.ToString();
 
        }
    }
}





Monday, May 19, 2014

LINQ Enumerable Except Example

C# > LINQ > Enumerable > Except

Produces the set difference of two sequences


Example

            double[] num1 = { 1.0, 1.1 , 1.2  };
            double[] num2 = { 1.1 };

            var onlyInNum1 = num1.Except(num2);

            foreach (double number in onlyInNum1)





Determining NLS_DATE_FORMAT Oracle

OracleNLS_DATE_FORMAT

NLS_DATE_FORMAT specifies the default date format to use with the TO_CHAR and TO_DATE functions

Example:
Get NLS_DATE_FORMAT 

SELECT value
FROM   nls_session_parameters
WHERE  parameter = 'NLS_DATE_FORMAT'

Result:





Friday, May 16, 2014

Change and replace text line in file C#

C# > IO > File > Read/Write Lines

ReadAllLines reads all lines of the file into a string array  and closes the file.
WriteAllLines creates a new file  writes strings to the file and closes the file.

Example:

Replace text line in a file

var lines = File.ReadAllLines(Pathfile);

lines[64] = "new text";


File.WriteAllLines(Pathfile);





Wednesday, May 14, 2014

Remove first character from string

C# > String > Substring

Remove first character from string

myString.Substring(1)





Tuesday, May 13, 2014

Check number is even or odd C#

C# > Operators > % Operator

Computes the remainder after dividing its first operand by its second.

Example: Check number is even or odd


  for (int x = 0; x < 100; x++)
  {
     if (x % 2 == 0)
      //even number
     else
      //odd number

  }











Tuesday, April 29, 2014

Find last modified tables Oracle

Oracle > Scripts

USER_TAB_MODIFICATIONS describes modifications to tables owned by the current user that have been modified since the last time statistics.

Example: Find last modified tables:

select * from USER_TAB_MODIFICATIONS order by timestamp desc