A Central Role

-
Technology
-
Leadership
Demystifying software engineering and everything in between
One of the alternative yet under utilized way to debug code in .NET is using Debug class found in System.Diagnostics Namespaces. This class really gives bunch of functionalities to developer that are very useful for debugging and I wonder why but I have observed that fewer percentage of developers use it. So I thought to share the usage of Debug class with developers out there as I found it very useful.
I will directly jump to code snippet demonstrating the functionality of Debug class:
using System.Collections.Generic;
using System.Diagnostics;
namespace DemoDebugClass
{
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
public static class CustomerExtensions
{
public static void PrintCustomersBelowAge25(this IEnumerablecustomersList)
{
foreach (var customer in customersList)
{
Debug.WriteLine(string.Format("Customer Name: {0}", customer.Name));
Debug.WriteLineIf(customer.Age < 25, "Required Customer Found!");
}
}
}
class Program
{
static void Main(string[] args)
{
ListcustomersList = new List ();
customersList.Add(new Customer { Id = 1, Age = 30, Name = "Customer A" });
customersList.Add(new Customer { Id = 2, Age = 15, Name = "Customer B" });
customersList.Add(new Customer { Id = 3, Age = 20, Name = "Customer C" });
customersList.PrintCustomersBelowAge25();
}
}
}
In the above code snippet, we have a customer class and assume that we are interested in finding customers below age 25 as shown in code snippet above. With the Debug.WriteLine you can print data to Output Window in Visual Studio (View –> Output Window) and even conditional data as well, as depicts in image below.
Now this is really interesting because it gives liberty to developers to debug the program and data without using breakpoints as most of us used to do. Further these lines are only executed when the program is executed in Debug mode. Besides, this also allows you to easily share the output log with your colleagues.
So go ahead and give it a try! If you don’t use it for some reason then please share your remarks in comments below. Happy Coding!
Good Job NED Volunteers
Source: http://www.devnextug.org/2011/04/sessions-on-web-development-using.html
On request of students from NED University of Engineering and Technology, DevNext User Group recently organized two day sessions on Web Development using ASP.NET at NED University. The sessions were held on 12th and 19th March, 2011.
The purpose of facilitating such sessions was to provide students firm understanding of web architecture and development using HTML, JavaScript, CSS and ASP.NET.
We would like to thank speaker and our volunteers at NED University for organizing such useful sessions.
About Speaker:
Mr. Anas Raza is a graduate in Computer and Information System from NED University and currently working as Software Engineer at ITIM Pakistan.
About DevNext User Group:
DevNext is a user group which has been created with the intention of providing a platform for the Next Generation Designers & Developers sharing and discussing knowledge regarding different tools and technologies. Our mission from inception has been to develop a peer group of developers, designers, architects, and managers who are interested in learning, sharing and growing their knowledge and capabilities. The group’s vision is to provide members with a forum to hear top industry experts speak, learn and teach others who are interested in the same technologies as you and are facing the same challenges.
Interested in organizing technology sessions in your University? Please contact us at contact@devnextug.org and we will be happy to assist you.