- Details
- Written by: Stanko Milosev
- Category: C#
- Hits: 1758
Create table with code like:
DataTable dtMaster = new DataTable("Master");In this example I will add Columns without specifying type:
dtMaster.Columns.Add("Id");Create new row:
DataRow drMaster = dtMaster.NewRow(); drMaster["Id"] = 1;Add row to DataTable:
dtMaster.Rows.Add(drMaster);Now details table:
DataTable dtDetail = new DataTable("Details"); dtDetail.Columns.Add("Id"); dtDetail.Columns.Add("FkDetailMasterId"); DataRow drDetail = dtDetail.NewRow(); drDetail["Id"] = 1; drDetail["FkDetailMasterId"] = 1; dtDetail.Rows.Add(drDetail);Create DataSet and add relation:
DataSet ds = new DataSet(); ds.Tables.Add(dtMaster); ds.Tables.Add(dtDetail); DataRelation relMasterDetail = new DataRelation("MyRelation" , ds.Tables["Master"].Columns["Id"] , ds.Tables["Details"].Columns["FkDetailMasterId"] ); ds.Relations.Add(relMasterDetail);Example download from here.
- Details
- Written by: Stanko Milosev
- Category: C#
- Hits: 1595
MethodInfoClass mic = new MethodInfoClass(); const BindingFlags bindingFlags = BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; System.Reflection.MethodInfo privateTestMethod = typeof(MethodInfoClass).GetMethod("PrivateTestMethod", bindingFlags); if (privateTestMethod is not null) { string returnFromPrivateTestMethod = (string)privateTestMethod.Invoke(mic, null); Console.WriteLine($"privateTestMethod: {returnFromPrivateTestMethod}"); }Example project download from here.
- Details
- Written by: Stanko Milosev
- Category: C#
- Hits: 1617
using System; using System.Collections; using System.Linq; namespace IEnumarable { class Program { static void Main(string[] args) { MyIEnumerable myIEnumerable = new MyIEnumerable(); foreach (string test in myIEnumerable.Cast<string>().ToList()) { Console.WriteLine(test); } } class MyIEnumerable : IEnumerable { private string _names = "stanko, milosev, elizabeta, lazarevic"; public IEnumerator GetEnumerator() { string[] aryNames = _names.Split(); foreach (string name in aryNames) { yield return name; } } } } }POI:
myIEnumerable.Cast
- Details
- Written by: Stanko Milosev
- Category: C#
- Hits: 1542
using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; namespace ConsoleApp15 { class Program { static void Main(string[] args) { string strXML = @" <doc> <ext>Type:A</ext> <ext>Type:B</ext> </doc>"; XElement myXML = XElement.Parse(strXML); IEnumerable<XElement> xElementData = from data in myXML.Descendants("ext") where data.Value.Contains("Type:A") select data; foreach (XElement xElement in xElementData) { Console.WriteLine(xElement.Value); } Console.ReadKey(); } } }POI:
IEnumerable