Notes
![]() ![]() Notes - notes.io |
filename: LinQ.cs
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class LinQ
{
/* public static void Main(String[] args)
{
String[] names =
{
"Ayan","Raman","Suman","Charles"
};
UsingLinQAnonymous(names);
UsingLinQTOXMLAddRemoveElement();
}*/
private static void UsingLinQ(String[] names)
{
IEnumerable<String> query= from s in names
where s.Length==5
orderby s
select s.ToUpper();
foreach(String s in query)
{
Console.WriteLine(s);
}
}
private static void UsingLinQExtension(String[] names)
{
IEnumerable<String> query = names.Where(s=>s.Length==5)
.OrderBy(s=>s).OrderBy(s=>s.ToUpper());
foreach (String s in query)
{
Console.WriteLine(s);
}
}
private static void UsingLinQFunction(String[] names)
{
Func<string, bool> filter = s => s.Length == 5;
Func<string, string> extract = s => s;
Func<string, string> project = s => s.ToUpper();
IEnumerable<String> query = names.Where(filter)
.OrderBy(extract).OrderBy(project);
foreach (String s in query)
{
Console.WriteLine(s);
}
}
private static void UsingLinQAnonymous(String[] names)
{
Func<string, bool> filter = delegate (string s)
{
return s.Length == 5;
};
Func<string, string> extract = delegate (string s)
{
return s;
}; ;
Func<string, string> project = delegate (string s)
{
return s.ToUpper();
}; ;
IEnumerable<String> query = names.Where(filter)
.OrderBy(extract).OrderBy(project);
foreach (String s in query)
{
Console.WriteLine(s);
}
}
private static void UsingLinQTOXML()
{
string myXML = @"<Departments>
<Department>Account </Department>
<Department>Sales </Department>
<Department>Marketing </Department>
</Departments>";
XDocument xDocument= new XDocument();
xDocument=XDocument.Parse(myXML);
var result = xDocument.Element("Departments").Descendants();
foreach (XElement item in result)
{
Console.WriteLine(item.Value);
}
}
private static void UsingLinQTOXMLAddRemoveElement()
{
string myXML = @"<Departments>
<Department>Account </Department>
<Department>Sales </Department>
<Department>Marketing </Department>
</Departments>";
XDocument xDocument = new XDocument();
xDocument = XDocument.Parse(myXML);
xDocument.Element("Departments").Add(new XElement("Department", "Technology"));
xDocument.Element("Departments").AddFirst(new XElement("Department", "Consulting"));
var result = xDocument.Element("Departments").Descendants();
foreach (XElement item in result)
{
Console.WriteLine(item.Value);
}
xDocument.Descendants().Where(s=>s.Value=="Sales").Remove();
var result1 = xDocument.Element("Departments").Descendants();
foreach (XElement items in result1)
{
Console.WriteLine(items.Value);
}
}
}
}
///////////////////////////LinQ////////////////////////
///////////////////////////////////////////Employee/////////////////////
filename: Employee.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Employee
{
public class Employees
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
/* class Program
{
public static void Main()
{
Employees[] empArray =
{
new Employees(){Id=100,Name="John",Age=18 },
new Employees(){Id=101,Name="Charles",Age=21 },
new Employees(){Id=102,Name="Rob",Age=20 },
new Employees(){Id=103,Name="Bill",Age=17 }
};
Employees[] teenAgeEmployee = empArray.Where(s => s.Age > 12 && s.Age < 20).ToArray();
foreach(Employees emp in teenAgeEmployee)
{
Console.WriteLine(emp.Name);
}
Employees bill = empArray.Where(s => s.Name == "Bill").FirstOrDefault();
Console.WriteLine(bill.Name);
Employees emp5 = empArray.Where(s => s.Id == 101).FirstOrDefault();
Console.WriteLine(emp5.Name);
}
}*/
}
}
///////////////////////////////////////////Employee/////////////////////
/////////////////Delegates///////////////////////
filename: Delegate.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
delegate void CustomDel(string s);
delegate int SumOperation(int i, int j);
internal class Delegate
{
static void Hello(string s)
{
Console.WriteLine($"Hello, {s}!!");
}
static void goodBye(string s)
{
Console.WriteLine($"Bye, {s}!!");
}
static int add(int i,int j)
{
return i + j;
}
/* static void Main()
{
CustomDel hiDel, byDel, multiDel, multiminus;
SumOperation sum;
hiDel = Hello;
byDel = goodBye;
multiDel = hiDel + byDel;
multiminus = multiDel - hiDel;
Console.WriteLine("Inviking Delegate");
hiDel("Ayan");
Console.WriteLine("Inviking Delegate");
byDel("Ayan");
Console.WriteLine("Inviking Delegate");
multiDel("Ayan");
Console.WriteLine("Inviking Delegate");
multiminus("Ayan");
//Console.Read();
sum = add;
Console.WriteLine("Inviking Delegate");
Console.WriteLine(sum(1, 2));
}*/
}
}
/////////////////Delegates///////////////////////
//////////////////////////Func Keyword////////////////////////
filename: FuncKeyword.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class FuncKeyword
{
static int add(int i, int j)
{
return i + j;
}
/* public static void Main()
{
Func<int, int, int> sum = add;
Console.WriteLine(sum(1,2));
}*/
}
}
//////////////////////////Func Keyword////////////////////////
//////////////////////////Action Keyword////////////////////////////
Filename: Action.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
internal class Action
{
static void add(int i, int j)
{
Console.WriteLine(i + j);
}
public static void Main()
{
Action<int,int> sum=add;
sum(1,2);
}
}
}
//////////////////////////Action Keyword////////////////////////////
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team