Object Oriented Programing Using C# .NET

January 28th, 2013 | Posted by Vidya Vrat in .NET | C# - (0 Comments)

Object-oriented programming (OOP) is the core ingredient of the .NET framework.  OOP is so important that, before embarking on the road to .NET, you must  understand its basic principles and terminology to write even a simple program.  The fundamental idea behind OOP is to combine into a single unit both data and  the methods that operate on that data; such units are called an object. All OOP  languages provide mechanisms that help you implement the object-oriented model.  They are encapsulation, inheritance, polymorphism and reusability. Let’s now  take a brief look at these concepts.

Read Full Article Here….

Agenda

  • OOP’s overview
  • Classes and Objects
  • Constructor and Destructor
  • Function Overloading
  • Encapsulation
  • Inheritance
  • Interface
  • Polymorphism

 

.NET Client Profile is supported by .NET Ver. 3.5 and 4.0. It is designed for client applications like Windows Forms. Client Profile version of .NET Framework is lightweight subset of Framework. This enables quicker deployment and small installation packages. 

Web Application doesn’t support Client Profile version of the Framework.

 

Microsoft has removed Client Profile from latest version of .NET Framework 4.5 and hence with .NET 4.5 there is no Client Profile as shown in the image below.

 

 

Microsoft just introduced a new certification track MTA, Microsoft Technology Associate.
This is designed for the people who are seeking an entry point into the Microsoft technology world.

This track has exams especially designed for topics like:

  • .NET Fundamentals
  • Windows Development Fundamentals
  • Web Development Fundamentals
  • Security Fundamentals
  • Networking Fundamentals
  • Windows Operating System Fundamentals

etc…..

These exams will establish  a solid base for new Microsoft technology aspirants to become MCTS or MCSD certified later on.

An already experienced developer/professional in Microsoft Technologies, does need to earn this MTA exam, but having one won’t hurt, as all that matters is Rock Solid Fundamentals.

 

 

EnterpriseLibrary version- 5.0 Download url
Language used in code sample below – C#Logging is a very important feature for many applications and serves the very critical purpose in a software application’s life. Logging enables to look for monitoring data and also document what is happening in-side and out-side of the application; also known as auditing.

Most common places to log such activities, information and data are:
1- Flat files (.log/.txt)
2- Event logs (Windows event viewer) and
3- Database.

In the absence of logging application block, the logging code needs to be repeated in the application at many places. This code will also include .NET library and function calls based on type of place you want to log the information. Hence, logging application block simply de-couples the logging functionality from the application code.

Configuring the Logging Application Block

1- Open your Visual Studio project, if not already available, add an app.config file
2- Open Microsoft Enterprise Library console.
3- In the Blocks menu, choose “Add Logging Settings” option, this will appear as shown here:
 

 

4- Based on your requirements add listners (File, Event, Database etc.).

 

 

 

5- Describe “Event Log” target listner


6- Describe “Flat File” trace listner

7- Describe “Message Formatter”

 

Now save this configuraton by clicking File–> Save option. and choose your added .config file,
this will be modified and will appear as shown here.

 

 

Now you can add the code to enable the Logging from your application into the defined “Target Trace Listners” in our case “Flat File” and “Event Log”.

I have designed a Windows Form application which reads a file, from provided path location, if file is found it loads the cntent into the text box, else in case of an exception “FileNotFoundException” the error info is logged into the Log file (c:\exception.log) and Event Log.

 

 

C# Code will look like this

 

using Microsoft.Practices.EnterpriseLibrary.Logging;

 

private voidbtnReadFile_Click(object sender, EventArgs e)

{

StreamReader sr = null;

 

try

{

sr = new StreamReader(txtFilePath.Text);

 

txtFileContent.Text = sr.ReadToEnd();

}

catch (FileNotFoundException)

{

txtFileContent.Text=“Exception details logged log file
and Event Viewer”;

 

LogEntry objLog = new LogEntry();

 

objLog.Message = “Please provide valid Filename”;

objLog.Categories.Add(“File Read Error”);

 

Logger.Write(objLog);

}

 

finally

{

if (sr != null)

{

sr.Close();

}

}

}

 

 

Now if you open the C:\Exception.log you will see:

 

—————————————-
Timestamp: 10/1/2012 7:35:03 PM

Message: There is no explicit mapping for the categories ‘File Read Error’. The log entry was:
Timestamp: 10/1/2012 7:35:03 PM
Message: Please provide valid Filename
Category: File Read Error
Priority: -1
EventId: 0
Severity: Information
Title:
Machine: VIDYAVRAT-PC
App Domain: LoggingApplicationBlock.vshost.exe
ProcessId: 9164
Process Name: C:\VidyaVrat\Microsoft .NET\Application Code POCs\EnterpriseLibrary-Application Blocks\LoggingApplicationBlock\LoggingApplicationBlock\bin\Debug\LoggingApplicationBlock.vshost.exe
Thread Name:
Win32 ThreadId:13588
Extended Properties:

Category:

Priority: -1

EventId: 6352

Severity: Error

Title:

Machine: VIDYAVRAT-PC

App Domain: LoggingApplicationBlock.vshost.exe

ProcessId: 9164

Process Name: C:\VidyaVrat\Microsoft .NET\Application Code POCs\EnterpriseLibrary-Application Blocks\LoggingApplicationBlock\LoggingApplicationBlock\bin\Debug\LoggingApplicationBlock.vshost.exe

Thread Name:

Win32 ThreadId:13588

Extended Properties:
—————————————-

 

Also, if you open the EventVwr.exe then you will see:

 

This concludes that how Logging application block enables you to write small amount of code to do such a critical task of auditing.

 

 

 

 

 

 

Normally an ADO .NET connection string uses “server” or “data source” to specify the machine name \ sql server instance, your application will be connecting to.

data source = .\sql instance name
server = .\sql instance name

SqlConnection conn = newSqlConnection(@”data source = .\sql2012;
                                         integrated security = true;
                                         database = AdventureWorks”);

But there are few more ways to specify the same

address = .\ sql instance name
addr = .\ sql instance name
network address = .\ sql instance name

 

using System;
using System.IO;
namespace FileRead_ExceptionHandling
{
class Program
{
static void Main(string[] args)
{
// declaring stream-reader here so it become accessible to the
// code blocks of try { } and finally { }
StreamReader sr = null;
try
{
// this assume you will have a file on C:\ as mentioned below
sr = new StreamReader(@”c:\TestCode2.log”);
string text = sr.ReadToEnd();

Console.WriteLine(text);
}

catch (FileNotFoundException ex)
{
Console.WriteLine(ex.Message + “\n
The wrong file name or path is provided!! Try Again”);
}
catch (Exception ex)
{
Console.WriteLine(“Try again” + ex.Message);
}

finally
{
if (sr != null)
{
sr.Close();
Console.WriteLine(“Stream closed”);
}
else
{
Console.WriteLine(“Stearm is Null”);
Console.WriteLine(“Try Again”);
}

// Performing stream-write operation to the same file
StreamWriter sw = new StreamWriter(@”c:\TestCode.log”, true);
sw.WriteLine(“Line 1”);
sw.Close();

Console.ReadLine();
}
}
}
}

 

 

Microsoft is committed to a program of Microsoft Certifications that are relevant, valued, and respected indicators of IT professional and developer technology skills. To fulfill this commitment, the Microsoft Certification team continually monitors current industry trends and evolves accordingly, developing new exams and discontinuing others to ensure that certification requirements keep pace with technology enhancements.

In accordance with this commitment, Microsoft Learning will retire 12 exams on March 31, 2009. These exams focus on technologies no longer included in Microsoft mainstream support, and are requirements for the Microsoft Certified Application Developer (MCAD), Microsoft Certified Solution Developer (MCSD), and Microsoft Certified Database Administrator (MCDBA) certifications. To complete these credentials, you must pass all required exams before they retire.

To know about the following:
• Developer exams that retire on March 31, 2009
• Microsoft SQL Server exams that retire on March 31, 2009
• Frequently asked questions

Read
MCP Exams being retired from 31-Mar-2009

I am passionate about helping people to excel in .NET. Hence, I give advice and mentoring to people who reach out to me personally. This mentorship comes free of cost.

Microsoft published the 1st CTP of VS201 and .NET 4.0 on 26-Oct-2008.

As of now its availavle in the form of virtual image only,follow the link below to download.

Download Vs2010 and .NET 4.0 CTP

Before you begin with download, lets have look at:

System Requirements
* Supported Operating Systems: Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP
* Minimum 75 GB available HDD space
* The host computer must have a minimum of 2 GB RAM, with 1 GB allocated to the host operating system and 1 GB allocated to the VPC.
* We recommend that the host computer CPU be at least a Core Duo 2 GHz processor.
Service Pack 1 of Microsoft Virtual PC 2007 is required to access the VPC.

Microsoft has launced a new section on MSDN for enhusiastic kids who wants to learn about computers, programming,VB .NET, C#, Window and Web applications.

This MSDN section provides various links for learning and downloading the development tools for kids.