Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
0
- Hands on Labs on build real Mobile Application and Backend services based on Azure. We will follow the diagram below in the deployment:
- App Services
- Functions & Logic Apps
- Application Insights – to monitor application that are in production
- Containers – simplify application deployments
- API Management
- SQL Databases
- Mobile DevOps & Xamarin
Also, here (https://github.com/MikeCodesDotNet/Mobile-Cloud-Workshop/tree/master/Walkthrough%20Guide/00_Setup) you will find the prerequisites for the workshop.
- Hands on Labs on build real Mobile Application and Backend services based on Azure. We will follow the diagram below in the deployment:
- App Services
- Functions & Logic Apps
- Application Insights – to monitor application that are in production
- Containers – simplify application deployments
- API Management
- SQL Databases
- Mobile DevOps & Xamarin
Also, here (https://github.com/MikeCodesDotNet/Mobile-Cloud-Workshop/tree/master/Walkthrough%20Guide/00_Setup) you will find the prerequisites for the workshop.
0
TO get sid of a user, wun following command:
wmic useraccount where name="USER" get sid
wmic useraccount get name,sid
in C# can check user UserSid:
var me = WindowsIdentity.GetCurrent();
SecurityIdentifier sid = me.User;
To get Group Policy of a user in domain use
gpresult /r
More info about gpresult
TO get sid of a user, wun following command:
wmic useraccount where name="USER" get sid
wmic useraccount get name,sid
in C# can check user UserSid:
var me = WindowsIdentity.GetCurrent();
SecurityIdentifier sid = me.User;
To get Group Policy of a user in domain use
gpresult /r
More info about gpresult
202
Posted on 5:00 AM by Softminer and filed under
C#
using (System.Diagnostics.EventLog eventLog = new System.Diagnostics.EventLog("Application")) { eventLog.Source = "Application"; eventLog.WriteEntry("Before Call", System.Diagnostics.EventLogEntryType.Information, 101, 1); }
0
Posted on 1:02 AM by Softminer and filed under
C#
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1.DateOfWeek { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string ret = GetStringFromWeek(); } private string GetStringFromWeek() { var d = DateTime.Now; System.Globalization.CultureInfo cul = System.Globalization.CultureInfo.CurrentCulture; var firstDayWeek = cul.Calendar.GetWeekOfYear( d, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday); int weekNum = cul.Calendar.GetWeekOfYear( d, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); int year = weekNum == 52 && d.Month == 1 ? d.Year - 1 : d.Year; switch(weekNum) { case 4: return "MA"; case 5: return "MB"; case 6: return "MB"; case 7: return "MB"; case 8: return "MB"; case 9: return "MB"; case 10: return "MB"; case 11: return "MB"; case 12: return "MB"; case 13: return "MB"; case 14: return "MB"; case 15: return "MB"; case 16: return "MB"; case 17: return "MB"; case 18: return "MB"; case 19: return "MB"; case 20: return "MB"; case 21: return "MB"; case 22: return "MB"; case 23: return "MB"; case 24: return "MB"; case 25: return "MB"; case 26: return "MB"; case 27: return "MB"; case 28: return "MB"; case 29: return "MB"; case 30: return "MB"; case 31: return "MB"; case 32: return "MB"; case 33: return "MB"; case 34: return "MB"; case 35: return "MB"; case 36: return "MB"; case 37: return "MB"; case 38: return "MB"; case 39: return "MB"; case 40: return "MB"; case 41: return "MB"; case 42: return "MB"; case 43: return "MB"; case 44: return "MB"; case 45: return "MB"; case 46: return "MB"; case 47: return "MB"; case 48: return "MB"; case 49: return "MB"; case 50: return "MB"; case 51: return "MB"; case 52: return "MB"; default: return "Default"; } return "test"; } private string GetDayoFWeek() { switch (DateTime.Now.DayOfWeek) { case DayOfWeek.Friday: return "F"; case DayOfWeek.Monday: return "M"; case DayOfWeek.Saturday: return "S"; case DayOfWeek.Sunday: return "M"; case DayOfWeek.Thursday: return "T"; case DayOfWeek.Tuesday: return "E"; case DayOfWeek.Wednesday: return "W"; } return "NO"; } } }
0
Summary of Technical Summit (Keynote)
Visual Studio online for project management, TFS
http://aka.ms/vsosecurity (microsoft security)
Some Shortcuts in visual studio
--------------------------------------------------------
Track active item in Solution explorer
Navigate To (Ctrl+comma)
Scrollbar (User map mode for vertical scrollbar)
Ctrl F10 (Run to Cursor)
http://en.wikipedia.org/wiki/HTTP_pipelining
OWIN defines a standard interface between .NET web servers and web applications.
Katana - OWIN implementations for Microsoft servers and frameworks
Open application insights is analytics for online projects
--------------------Xamarin------------------------------
Xamarin forms is available for business accounts, On Xamarin forms standard control can be used and it will replaced by device user control, Xamarin forms dont have UI designer currently.
PCL = Portable class library as a share library in Xamarin project
Yumtoso is an example of Xamarin project which is online ( A universal App)
http://winstoredev.com/yumtoso-fastfood-app/
Xamarin generate pure Objective C code
NO IL-code
.Net runtime
Genymotion is an android simulator on MAC os
Mobile web app ui design
http://www.telerik.com/kendo-ui1
Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer from JavaScript. Combined with a UI framework such as jQuery Mobile or Dojo Mobile or Sencha Touch, this allows a smartphone app to be developed with just HTML, CSS, and JavaScript.
Bower.io is a package manager for web
ionic
npmjs package installer
http://www.visualstudio.com/en-us/explore/cordova-vs.aspx
Cross platform application
Tools for Apache Cordova Update: iOS Debugging & Windows 8.1 Support
Video Presentation
--------------------------------------------------------------------------------
asp.net Next version
http://www.asp.net/vnext
http://www.asp.net/vnext/overview/aspnet-vnext/vc
http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview
http://msdn.microsoft.com/en-us/library/dn481095.aspx
Announcing ASP.NET features in Visual Studio 2015 Preview and VS2013 Update 4
Release management for visual studio 2013
----------------------------------------------------------------------
Some related video can be found on Channel 9 http://channel9.msdn.com/Events/TechEd/Europe/2014
News about .Net Open source
Summary of Technical Summit (Keynote)
Visual Studio online for project management, TFS
http://aka.ms/vsosecurity (microsoft security)
Some Shortcuts in visual studio
--------------------------------------------------------
Track active item in Solution explorer
Navigate To (Ctrl+comma)
Scrollbar (User map mode for vertical scrollbar)
Ctrl F10 (Run to Cursor)
http://en.wikipedia.org/wiki/HTTP_pipelining
OWIN defines a standard interface between .NET web servers and web applications.
Katana - OWIN implementations for Microsoft servers and frameworks
Open application insights is analytics for online projects
--------------------Xamarin------------------------------
Xamarin forms is available for business accounts, On Xamarin forms standard control can be used and it will replaced by device user control, Xamarin forms dont have UI designer currently.
PCL = Portable class library as a share library in Xamarin project
Yumtoso is an example of Xamarin project which is online ( A universal App)
http://winstoredev.com/yumtoso-fastfood-app/
Xamarin generate pure Objective C code
NO IL-code
.Net runtime
Genymotion is an android simulator on MAC os
Mobile web app ui design
http://www.telerik.com/kendo-ui1
Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer from JavaScript. Combined with a UI framework such as jQuery Mobile or Dojo Mobile or Sencha Touch, this allows a smartphone app to be developed with just HTML, CSS, and JavaScript.
Bower.io is a package manager for web
ionic
npmjs package installer
http://www.visualstudio.com/en-us/explore/cordova-vs.aspx
Cross platform application
Tools for Apache Cordova Update: iOS Debugging & Windows 8.1 Support
Video Presentation
--------------------------------------------------------------------------------
asp.net Next version
http://www.asp.net/vnext
http://www.asp.net/vnext/overview/aspnet-vnext/vc
http://www.asp.net/vnext/overview/aspnet-vnext/aspnet-5-overview
http://msdn.microsoft.com/en-us/library/dn481095.aspx
Announcing ASP.NET features in Visual Studio 2015 Preview and VS2013 Update 4
Release management for visual studio 2013
----------------------------------------------------------------------
Some related video can be found on Channel 9 http://channel9.msdn.com/Events/TechEd/Europe/2014
News about .Net Open source
0
Here is a good example of publish subscribe design pattern in c#
http://www.codeproject.com/Articles/34316/Topic-based-Publish-Subscribe-design-pattern-imple
Here you can read about Publish Subscribe design pattern
http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern
WCF has already some method to implement it
http://www.codeproject.com/Articles/34333/Topic-based-publish-subscribe-design-pattern-imp
Here is a good example of publish subscribe design pattern in c#
http://www.codeproject.com/Articles/34316/Topic-based-Publish-Subscribe-design-pattern-imple
Here you can read about Publish Subscribe design pattern
http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern
WCF has already some method to implement it
http://www.codeproject.com/Articles/34333/Topic-based-publish-subscribe-design-pattern-imp
0
To install TFS 2013 you need to install SQL server 2012 or 2014
Look at the requirement here
http://msdn.microsoft.com/en-us/library/dn641202.aspx
After installation you have to create new TeamProject
and choose a process template for that, Here is the default process template
http://msdn.microsoft.com/en-us/library/ff731587.aspx
To be able to customize a template you should be able to download the template, edit it and upload it
http://msdn.microsoft.com/en-us/library/ms243782.aspx
Modify or add custom work Item
http://msdn.microsoft.com/en-us/library/hh409273.aspx
To install TFS 2013 you need to install SQL server 2012 or 2014
Look at the requirement here
http://msdn.microsoft.com/en-us/library/dn641202.aspx
After installation you have to create new TeamProject
and choose a process template for that, Here is the default process template
http://msdn.microsoft.com/en-us/library/ff731587.aspx
To be able to customize a template you should be able to download the template, edit it and upload it
http://msdn.microsoft.com/en-us/library/ms243782.aspx
Modify or add custom work Item
http://msdn.microsoft.com/en-us/library/hh409273.aspx
0
This is a tutorial to test webservice using Ranorex
http://www.ranorex.com/blog/how-to-test-web-services-with-ranorex
To test following asp.net webservice can be used.
http://www.w3schools.com/webservices/tempconvert.asmx
This is a tutorial to test webservice using Ranorex
http://www.ranorex.com/blog/how-to-test-web-services-with-ranorex
To test following asp.net webservice can be used.
http://www.w3schools.com/webservices/tempconvert.asmx
0
To Generate Service proxy c# classes from WCF endpoint Run:
cd C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin>
svcutil net.tcp://endpoint.svc /out:c:\proxy
To create schema from service contract dll
Run visual studio command prompt as admin:
go to the output folder
Svcutil c:/ServiceContracts.dll /t:metadata
Schema (*.xsd) and (*.wsdl) are generated and then proxy classes can be generated using:
Svcutil *.wsdl *.xsd /language:C#
To Generate Service proxy c# classes from WCF endpoint Run:
cd C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin>
svcutil net.tcp://endpoint.svc /out:c:\proxy
To create schema from service contract dll
Run visual studio command prompt as admin:
go to the output folder
Svcutil c:/ServiceContracts.dll /t:metadata
Schema (*.xsd) and (*.wsdl) are generated and then proxy classes can be generated using:
Svcutil *.wsdl *.xsd /language:C#
0
The Dynamic IP Restrictions Extension for IIS provides IT Professionals and Hosters a configurable module that helps mitigate or block Denial of Service Attacks or cracking of passwords through Brute-force by temporarily blocking Internet Protocol (IP) addresses of HTTP clients who follow a pattern that could be conducive to one of such attacks. This module can be configured such that the analysis and blocking could be done at the Web Server or the Web Site level.
http://www.iis.net/downloads/microsoft/dynamic-ip-restrictions
Posted on 5:21 AM by Softminer and filed under
C#
The Dynamic IP Restrictions Extension for IIS provides IT Professionals and Hosters a configurable module that helps mitigate or block Denial of Service Attacks or cracking of passwords through Brute-force by temporarily blocking Internet Protocol (IP) addresses of HTTP clients who follow a pattern that could be conducive to one of such attacks. This module can be configured such that the analysis and blocking could be done at the Web Server or the Web Site level.
http://www.iis.net/downloads/microsoft/dynamic-ip-restrictions
using System; using System.Collections.Generic; using System.Timers; using System.Web; public partial class _Default : System.Web.UI.Page { private static Dictionary<string, short> _IpAdresses = new Dictionary<string, short>(); private static Stack<string> _Banned = new Stack<string>(); private static Timer _Timer = CreateTimer(); private static Timer _BannedTimer = CreateBanningTimer(); private const int BANNED_REQUESTS = 10; private const int REDUCTION_INTERVAL = 1000; // 1 second private const int RELEASE_INTERVAL = 5 * 60 * 1000; // 5 minutes protected void Page_Load(object sender, EventArgs e) { string ip = HttpContext.Current.Request.UserHostAddress; if (_Banned.Contains(ip)) { HttpContext.Current.Response.StatusCode = 403; HttpContext.Current.Response.End(); } CheckIpAddress(ip); } /// <summary> /// Checks the requesting IP address in the collection /// and bannes the IP if required. /// </summary> private static void CheckIpAddress(string ip) { if (!_IpAdresses.ContainsKey(ip)) { _IpAdresses[ip] = 1; } else if (_IpAdresses[ip] == BANNED_REQUESTS) { _Banned.Push(ip); _IpAdresses.Remove(ip); } else { _IpAdresses[ip]++; } } #region Timers /// <summary> /// Creates the timer that substract a request /// from the _IpAddress dictionary. /// </summary> private static Timer CreateTimer() { Timer timer = GetTimer(REDUCTION_INTERVAL); timer.Elapsed += new ElapsedEventHandler(TimerElapsed); return timer; } /// <summary> /// Creates the timer that removes 1 banned IP address /// everytime the timer is elapsed. /// </summary> /// <returns></returns> private static Timer CreateBanningTimer() { Timer timer = GetTimer(RELEASE_INTERVAL); timer.Elapsed += delegate { _Banned.Pop(); }; return timer; } /// <summary> /// Creates a simple timer instance and starts it. /// </summary> /// <param name="interval">The interval in milliseconds.</param> private static Timer GetTimer(int interval) { Timer timer = new Timer(); timer.Interval = interval; timer.Start(); return timer; } /// <summary> /// Substracts a request from each IP address in the collection. /// </summary> private static void TimerElapsed(object sender, ElapsedEventArgs e) { foreach (string key in _IpAdresses.Keys) { _IpAdresses[key]--; if (_IpAdresses[key] == 0) _IpAdresses.Remove(key); } } #endregion }
0
protected void Application_BeginRequest(object sender, EventArgs e) { String fullOrigionalpath = Request.Url.ToString(); if (fullOrigionalpath.Contains("?p=")) { string website = "http://" + Request.Url.Authority; Response.Clear(); //Response.StatusCode = 301; Response.Status = "301 Moved Permanently"; //Response.Redirect(fullOrigionalpath.Replace("default.aspx?p=", "") + "/"); Response.AddHeader("Location", website + "/" + Request.QueryString["p"].ToString() + "/"); Response.End(); } }
0
Posted on 3:31 AM by Softminer and filed under
C#
static void Main(string[] internal args) { // https://www.cloudflare.com/api_json.html \ // -d 'a=zone_file_purge' \ //-d 'tkn=8afbe6dea02407989af4dd4c97bb6e25' \ //-d 'email=sample@example.com' \ //-d 'z=example.com' \ //-d 'url=http://www.example.com/style.css' // Create a request using a URL that can receive a post. WebRequest request = WebRequest.Create ("https://www.cloudflare.com/api_json.html"); request.Proxy = null; request.Credentials = CredentialCache.DefaultCredentials; //ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); // Set the Method property of the request to POST. request.Method = "POST"; // Create POST data and convert it to a byte array. string postData = string.Format("a={0}&tkn={1}&email={2}&z={3}&url={4}", ); byte[] internal byteArray = Encoding.UTF8.GetBytes (postData); // Set the ContentType property of the WebRequest. request.ContentType = "application/x-www-form-urlencoded"; // Set the ContentLength property of the WebRequest. request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream (); // Write the data to the request stream. dataStream.Write (byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close (); // Get the response. WebResponse response = request.GetResponse (); // Display the status. Console.WriteLine (((HttpWebResponse)response).StatusDescription); // Get the stream containing content returned by the server. dataStream = response.GetResponseStream (); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader (dataStream); // Read the content. string responseFromServer = reader.ReadToEnd (); // Display the content. Console.WriteLine (responseFromServer); // Clean up the streams. reader.Close (); dataStream.Close (); response.Close (); } public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
0
Fixing nested HtmlAgility SelectSingleNode
Posted on 2:51 AM by Softminer and filed under
C#
Fixing nested HtmlAgility SelectSingleNode
var firstDiv = page.DocumentNode.SelectSingleNode("//div"); //Returns the first div on the page, as it should. But you cannot dig into this. var firstDivTitle = firstDiv.SelectSingleNode("//h2"); // This returns the first <h2> on the entire page, not the one in the div. To fix it you have to write var firstDivTitle = firstDiv.SelectSingleNode(".//h2"); another solution is to mix the tags var firstDivTitle = page.DocumentNode.SelectSingleNode("//div//h2");
0
1.First you have to create a profile
C:\Program Files (x86)\Mozilla Firefox\firefox.exe -p
profiles are saved in
C:\Users\administrator\AppData\Roaming\Mozilla\Firefox\Profiles\lrnq8wmb.selenium
2.Add profile to selenium driver
1.First you have to create a profile
C:\Program Files (x86)\Mozilla Firefox\firefox.exe -p
profiles are saved in
C:\Users\administrator\AppData\Roaming\Mozilla\Firefox\Profiles\lrnq8wmb.selenium
2.Add profile to selenium driver
OpenQA.Selenium.Firefox.FirefoxProfile profile = new FirefoxProfile(@"~path"); IWebDriver driver = new OpenQA.Selenium.Firefox.FirefoxDriver(profile);
2
Posted on 5:46 AM by Softminer and filed under
C#,
Visual Studio
Task[] tasks = new Task[1000]; for (int i = 0; i < 1000; i++) { tasks[i] = Task.Factory.StartNew(() => { Console.WriteLine(System.DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")); }); } Task.WaitAll(tasks);
0
From Control panel -> Turn windows features on or off its possible to install windows Message Queuing
http://technet.microsoft.com/en-us/library/cc730960.aspx
To Send and recieve message using c# first you have to create a message queue:
http://www.codeproject.com/Articles/5830/Using-MSMQ-from-C
if(MessageQueue.Exists(@".\Private$\MyQueue"))
//creates an instance MessageQueue, which points
//to the already existing MyQueue
mq = new System.Messaging.MessageQueue(@".\Private$\MyQueue");
else
//creates a new private queue called MyQueue
mq = MessageQueue.Create(@".\Private$\MyQueue");
To Send message
System.Messaging.Message mm = new System.Messaging.Message();
mm.Body = txtMsg.Text;
mm.Label = "Msg" + j.ToString();
mq.Send(mm);
and to recieve message
try
{
mes = mq.Receive(new TimeSpan(0, 0, 3));
mes.Formatter = new XmlMessageFormatter(
new String[] {"System.String,mscorlib"});
m = mes.Body.ToString();
}
catch
{
m = "No Message";
}
MsgBox.Items.Add(m.ToString())
to See messages in windows open Computer Management and from Service applications -> Message Queuing
From Control panel -> Turn windows features on or off its possible to install windows Message Queuing
http://technet.microsoft.com/en-us/library/cc730960.aspx
To Send and recieve message using c# first you have to create a message queue:
http://www.codeproject.com/Articles/5830/Using-MSMQ-from-C
if(MessageQueue.Exists(@".\Private$\MyQueue"))
//creates an instance MessageQueue, which points
//to the already existing MyQueue
mq = new System.Messaging.MessageQueue(@".\Private$\MyQueue");
else
//creates a new private queue called MyQueue
mq = MessageQueue.Create(@".\Private$\MyQueue");
To Send message
System.Messaging.Message mm = new System.Messaging.Message();
mm.Body = txtMsg.Text;
mm.Label = "Msg" + j.ToString();
mq.Send(mm);
and to recieve message
try
{
mes = mq.Receive(new TimeSpan(0, 0, 3));
mes.Formatter = new XmlMessageFormatter(
new String[] {"System.String,mscorlib"});
m = mes.Body.ToString();
}
catch
{
m = "No Message";
}
MsgBox.Items.Add(m.ToString())
to See messages in windows open Computer Management and from Service applications -> Message Queuing

0
Here is an example of Range-Specific Request in ASP.NET
, Sample
Posted on 5:33 AM by Softminer and filed under
C#
public void ProcessRequest(HttpContext context) { String FileName = "Test.mp4"; String FilePath = "Test.mp4"; System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.ClearContent(); response.Clear(); response.ContentType = "video/mpeg"; response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";"); response.AppendHeader("Access-Control-Allow-Origin", "*"); response.TransmitFile(FilePath); response.Flush(); response.End(); }
Here is an example of Range-Specific Request in ASP.NET
, Sample
0
Visual studio should run as Administrator:
Posted on 8:56 AM by Softminer and filed under
C#
Visual studio should run as Administrator:
Process cmd = new Process(); ProcessStartInfo info = new ProcessStartInfo(@"cmd.exe", ""); info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; info.WorkingDirectory = @"c:\"; info.RedirectStandardInput = true; info.RedirectStandardOutput = true; info.RedirectStandardError = true; info.UseShellExecute = false; info.CreateNoWindow = true; cmd.StartInfo = info; cmd.Start(); cmd.StandardInput.WriteLine(@"c:\Windows\system32\inetsrv\appcmd recycle apppool /apppool.name:DefaultAppPool"); cmd.StandardInput.Flush(); cmd.StandardInput.Close(); string output = cmd.StandardOutput.ReadToEnd();
0
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
Posted on 3:29 AM by Softminer and filed under
C#,
Visual Studio
Define an interface for creating an object, but let subclasses decide which class to instantiate. Factory Method lets a class defer instantiation to subclasses.
// Factory Method pattern -- Structural example using System; namespace DoFactory.GangOfFour.Factory.Structural { /// <summary> /// MainApp startup class for Structural /// Factory Method Design Pattern. /// </summary> class MainApp { /// <summary> /// Entry point into console application. /// </summary> static void Main() { // An array of creators Creator[] creators = new Creator[2]; creators[0] = new ConcreteCreatorA(); creators[1] = new ConcreteCreatorB(); // Iterate over creators and create products foreach (Creator creator in creators) { Product product = creator.FactoryMethod(); Console.WriteLine("Created {0}", product.GetType().Name); } // Wait for user Console.ReadKey(); } } /// <summary> /// The 'Product' abstract class /// </summary> abstract class Product { } /// <summary> /// A 'ConcreteProduct' class /// </summary> class ConcreteProductA : Product { } /// <summary> /// A 'ConcreteProduct' class /// </summary> class ConcreteProductB : Product { } /// <summary> /// The 'Creator' abstract class /// </summary> abstract class Creator { public abstract Product FactoryMethod(); } /// <summary> /// A 'ConcreteCreator' class /// </summary> class ConcreteCreatorA : Creator { public override Product FactoryMethod() { return new ConcreteProductA(); } } /// <summary> /// A 'ConcreteCreator' class /// </summary> class ConcreteCreatorB : Creator { public override Product FactoryMethod() { return new ConcreteProductB(); } } }
2
Posted on 2:12 AM by Softminer and filed under
C#,
Visual Studio
using System; using System.Threading.Tasks; namespace Listing_02 { class Listing_02 { static void Main(string[] args) { // use an Action delegate and a named method Task task1 = new Task(new Action(printMessage)); // use a anonymous delegate Task task2 = new Task(delegate { printMessage(); }); // use a lambda expression and a named method Task task3 = new Task(() => printMessage()); // use a lambda expression and an anonymous method Task task4 = new Task(() => { printMessage(); }); task1.Start(); task2.Start(); task3.Start(); task4.Start(); // wait for input before exiting Console.WriteLine("Main method complete. Press enter to finish."); Console.ReadLine(); } static void printMessage() { Console.WriteLine("Hello World"); } } }