C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Sample program using feilds,constructors,properties


Posted Date: 20 Dec 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: priyankaMember Level: Silver    
Rating: 1 out of 5Points: 7



A Sample Program in C# using Feilds, Constructors and Properties


using System;

namespace samplesql
{
class friend
{
public string name;
public int age;
public bool married;

public friend()
{
}
public friend(string name1, int age1)
{
name = name1;
age = age1;
}
public friend(string name2, int age2, bool married2)
{
name = name2;
age = age2;
married = married2;
}

public string frdname
{
get { return name; }
set { name = value; }
}
public int frdage
{
get { return age; }
set
{
if (value < 100)
{
age = value;
}
else
{
Console.Write("ERROR");
}
}
}
public bool frdmarried
{
get { return married; }
set
{
married = value;
}
}
}
class program
{
public static void Main(string[] args)
{
friend f1 = new friend();

Console.Write("1.Name:");
f1.frdname = Console.ReadLine();
Console.Write("Age:");
f1.frdage = Convert.ToInt16(Console.ReadLine());

friend f2 = new friend("Priyanka", 22);

friend f3 = new friend();

Console.Write("3.Enter the Name :");
f3.frdname = Console.ReadLine();
Console.Write("Enter Age:");
f3.frdage = Convert.ToInt16(Console.ReadLine());
if (f3.frdage > 20)
{
f3.frdmarried = true;
}
else
{
f3.frdmarried = false;
}

Console.WriteLine("Name and Age: {0},{1}", f1.frdname, f1.frdage);
Console.WriteLine("Name and Age: {0},{1}", f2.frdname, f2.frdage);
Console.WriteLine("Name, Age and Married or Not: {0},{1},{2}", f3.frdname, f3.frdage, f3.frdmarried);

Console.ReadLine();
}
}
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Use a session variable in the class files in c# ASP.Net
Previous Resource: Export an SQL SERVER data table to an excel sheet
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use