return and yield return , break and yield break.

C# does not allow yield all by itself – only yield return and yield break.

yield is a contextual keyword that is only recognized inside iterator blocks and only in conjunction with either return or break.

One example case where yield-return is preferable is if the IEnumerable represents an infinite set. Consider the list of Prime Numbers, or an infinite list of random numbers. You can never return the full IEnumerable at once, so you use yield-return to return the list incrementally.
http://www.davidgiard.com/2009/09/13/YieldReturnAndYieldBreakInC.aspx

http://www.codeproject.com/Articles/38097/The-Mystery-Behind-Yield-Return

 

Advertisements
By Sriramjithendra Posted in C#.NET

Convert EntityCollection to DataTable.

//Get records returns the Entity Collection
public DataTable GetDataTable()
{
    EntityCollection accountRecords = GetAccountRecords();
    DataTable dTable = new DataTable();
    int iElement = 0;

    if (accountRecords.Entities.Count >= 0)
    {
        return;
    }

    //Defining the ColumnName for the datatable
    for (iElement = 0; iElement <= accountRecords.Entities[0].Attributes.Count - 1; iElement++)
    {
        string columnName = accountRecords.Entities[0].Attributes.Keys.ElementAt(iElement);
        dTable.Columns.Add(columnName);
    }

    foreach (Entity entity in accountRecords.Entities)
    {
        DataRow dRow = dTable.NewRow();
        for (int i = 0; i <= entity.Attributes.Count - 1; i++)
        {
            string colName = entity.Attributes.Keys.ElementAt(i);
            dRow[colName] = entity.Attributes.Values.ElementAt(i);
        }
        dTable.Rows.Add(dRow);
    }
    return dTable;
}


http://www.codeproject.com/Tips/553146/Convert-EntityCollection-to-DataTable
By Sriramjithendra Posted in C#.NET

CONVERTING DATASET to XML string

Public Shared Function GetXMLstring(ByVal ds As DataSet) As String
Dim xEle As XElement = New XElement(“Items”)

For Each tb As DataTable In ds.Tables
Dim xEleLevel1 As XElement = New XElement(tb.TableName.Replace(” “, “”))
xEle.Add(xEleLevel1)
For Each row In tb.Rows
Dim xEleLevel2 As XElement = New XElement(“Item”)
xEleLevel1.Add(xEleLevel2)
For Each col As DataColumn In tb.Columns
xEleLevel2.Add(New XElement(col.ColumnName, row(col.ColumnName)))
Next
Next

Next

Return xEle.ToString()
End Function

By Sriramjithendra Posted in C#.NET