gs gs108 Delegates, Generics and LINQ - Operation and Query with LINQ - Quiz No.1
gs gs108 CSharp Quiz
This quiz belongs to book/course code gs gs108 CSharp of gs organization. We have 110 quizzes available related to the book/course CSharp. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Delegates, Generics and LINQ. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
class Program { static void Main(string[] args) { string[] strs = {"alpha", "beta", "gamma"}; var chrs = from str in strs let chrArray = str.ToCharArray() from ch in chrArray orderby ch select ch; Console.WriteLine("The individual characters in sorted order:"); foreach (char c in chrs) Console.Write(c + " "); Console.WriteLine(); Console.ReadLine(); } }
class Program { static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; var posNums = nums.Where(n => n > 0).Select(r => r*2). OrderByDescending(r=>r); Console.Write("The positive values in nums: "); foreach(int i in posNums) Console.Write(i + " "); Console.WriteLine(); Console.ReadLine(); } }
class Program { static void Main(string[] args) { int[] nums = {3, 1, 2, 5, 4}; var ltAvg = from n in nums let x = nums.Average() where n < x select n; Console.WriteLine("The average is " + nums.Average()); Console.ReadLine(); } }
class Program { static void Main(string[] args) { Expression<Func<int, int, bool>> IsFactorExp = (n, d) => (d != 0) ? (n % d) == 0 : false; Func<int, int, bool> IsFactor = IsFactorExp.Compile(); if (IsFactor(10, 5)) Console.WriteLine("5 is a factor of 10."); if (!IsFactor(343, 7)) Console.WriteLine("7 is not a factor of 10."); Console.ReadLine(); } }
5 is a factor of 10 7 is not a factor of 10
class Program { static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; int len = /*_________________ */ Console.WriteLine("The number of positive values in nums: " + len); Console.ReadLine(); } }
from n in nums where n > 0 select n
from n in nums where n > 0 select n.Count()
(from n in nums where n > 0 select n).Count();
class Program { static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; var posNums = from n in nums where n > 0 select n; int len = posNums.Count(); Console.WriteLine(len); Console.ReadLine(); } }
class Program { static void Main(string[] args) { int[] nums = { 1, -2, 3, 0, -4, 5 }; var posNums = nums.Where(n => n < 10).Select(r => r%3); Console.Write("The values in nums: "); foreach (int i in posNums) Console.Write(i + " "); Console.WriteLine(); Console.ReadLine(); } }
class Program { static void Main(string[] args) { string[] strs = { ".com", ".net", "facebook.com", "google.net", "test", "netflix.net", "hsNameD.com" }; var netAddrs = from addr in strs where addr.Length > 4 && addr.EndsWith(".net", StringComparison.Ordinal) select addr; foreach (var str in netAddrs) Console.WriteLine(str); Console.ReadLine(); } }
facebook.com netflix.net google.net
google.net netflix.net
class Program { static void Main(string[] args) { int[] nums = { 1, -2, -3, 5 }; var posNums = from n in nums orderby n descending select n*4 / 2; Console.Write("The values in nums: "); foreach (int i in posNums) Console.Write(i + " "); Console.WriteLine(); Console.ReadLine(); } }