Tuesday, July 8, 2014

C# Tutorial for Beginners 22 - Properties in C# (How to Define Properti...

9:44 PM









1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
namespace MyProject.Examples
{
public class Book
{
private int _id;
private string _bookName;
private int _noOfPAges=250;
private string _auther;


public string Auther{get; set;}


public int Id
{
set
{
if (value < 0)
throw new Exception("Id not valid");
this._id = value;
}
get {
return this._id;
}
}



public string BookName
{
set
{
if (string.IsNullOrEmpty(value))
throw new Exception("Book Name not valid or null");
this._bookName = value;
}
get {
return this._bookName;
}
}


public int NoOfPAge
{
get
{
return this._noOfPAges;
}
}
}


class ExampleOne
{
public static void Main()
{

Book B1 =new Book();
B1.Id=10;
B1.BookName = "The C# Book";
B1.Auther = "ProgrammingKnowldge";
Console.WriteLine("The Book Id is {0}", B1.Id);
Console.WriteLine("The Book Name is {0}", B1.BookName);
Console.WriteLine("The Book Page is {0}", B1.NoOfPAge);
Console.WriteLine("The Book Auther is {0}", B1.Auther);
Console.ReadKey();
}
}
}














---------------------------------------------------------------------

earches related to properties c#

extension properties c#

use properties c#

writing properties in c#

override properties c#

private properties c#

class properties c#

properties.settings c#

constructor c#

Searches related to property c#

automatic property c#

virtual property c#

nonserialized property c#

property c# interface

property c# default value

override property c#

private set property c#

private property c#

Using Properties (C# Programming Guide)

Written by

We are one of the initiators of the development of information technology in understanding the need for a solution that is familiar and close to us.

0 comments:

Post a Comment

 

© 2013 Klick Dev. All rights resevered.

Back To Top