Facebook Twitter Gplus LinkedIn YouTube Google Maps RSS
Home Posts tagged "C#" (Page 2)
formats

Default Access Specifiers

Published on July 29, 2010 by in Technical

n enum has default modifier as public

A class has default modifiers as private . It can declare members (methods etc) with following access modifiers:
public
internal
private
protected internal

An interface has default modifier as public

A struct has default modifier as private and it can declare its members (methods etc) with following access modifiers:
public
internal
private

A methods, fields, and properties has default access modifier as “Private” if no modifier is specified.

 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Static Methods

1. Use them for converters
2. When you have to use the same method again and again in several locations.

 
Tags: ,
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Read Only Vs Property with Get

There is no difference in functionality.
Its just a developers preference.
Ex:
READ ONLY:
private readonly string Test;

PROPERTY WITH GET
private string _test;
Public string Test{ get { return _test; }}

 
Tags:
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
formats

Nullable types

Definition

A nullable Type is a  data type is  that contain the defined data type or the value of null.

You should note here that here variable datatype has been given and then only it can be used.

This nullable type concept is not comaptible with “var”.

I will explain this with syntax in next section.

Declaration:

Any DataType   can be declared  nullable type with the help of operator “?”.

Example of the syntax is as Follows :-

int? i = null;

 
Tags:
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
2 Comments  comments 
formats

this this this

Published on April 4, 2010 by in Technical

It took me a while to get the concept right.
Couple of examples on how to use this.
Ex 1:
public class TestClass
{
int val;
TestClass(val)
{
//Scenario 1
this.val= val;
//Scenario 2
val=val;
}
}

In Scenario 1, the local variable will be set. In the 2nd scenario, the value passed will be assigned to itself.

Example 2:
This required my attention.

public class TestClass
{
int i =100;
string str = “Test”;
public TestClass()
{
TestOtherClass _toc = new TestOtherClass(this);
console.writeline(_toc.TestOtherMethod());
//Output will be 100Test
}
}

 
Tags:
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 
© All rights reserved to Cyberbrutus. 2012
credit

Switch to our mobile site