Académique Documents
Professionnel Documents
Culture Documents
Day 2
• Interface
• Properties
• Indexers
• Collections
• Compiler Switches
• Assemblies
– Private
– Public
– Versioning
E.g.:
public interface ITextBox : IControl {
………………. // interface body
}
• All the interface members are public by default. This is because any class
or struct in the program can access the interface members.
interface IShape {
void Draw(); // interface method declaration
}
Interface
Interface
• No access modifier
– An interface does not provide any implementation code. This will be done by the
classes that implement the interface. An interface is said to provide a specification or
guideline for what will be happening, but not the details.
– Interfaces contain only methods, properties, events and indexers. They do not
contain data members, constructors, or destructors.
interface IAdd {
void Add ( int a, int b);
}
class Calculate{
public void IAdd.Add ( int a, int b) {
……………………. // method body
}
}
interface IAdd {
void Add ( int a, int b); // method declaration
}
System.Console.WriteLine(“Point 1: {0},{1})”,
starting.iPointx1, starting.iPointy1);
System.Console.WriteLine(“Point 2: {0},{1})”,
ending.iPointx1, ending.iPointy1);
}
}
Properties Properties
(Class1.cs) (Class2.cs)
Indexer Properties
Directive Description
Indexer(Class1.cs)
#define DEBUG
Using System;
Using System.IO;
string buffer;
StreamReader myFile = File.OpenText(args[0]);
while ( buffer = myfile.ReadLine()) != null )
{
#if DEBUG
Console.Write( “{0:D3} –”, buffer.Length);
#endif
Console.WriteLine(buffer);
}
myFile.Close();
}
}
}
Copyright © 2005, 23 ER/CORP/CRS/LA30FC/003
Infosys Technologies Ltd Version no: 2.0
Collection
• A collection is a specialized class that organizes and exposes a group of
objects.
• The list of objects managed by the Array List is a zero based collection.
• The items in the list are retrieved by accessing the item index.
• Methods
– Add()
– Remove()
– RemoveAt()
• Property
– Indexer
– Count
ArrayList
• Methods
– Add()
– Remove()
• Property HashTable
– Indexer
– Count
• /out:filename
– Can specify the name of the output file
– csc /out:firstprogram.exe firstc.cs
• /target:exe
• /target:library
• /target:module
• /target:winexe
– Can specify the type of output file
• Error report
• /bugreport:file
– Can generate an error report, all the compilation errors are stored in the file
– csc /bugreport:error.txt firstc#.cs
• Contains
– Copy of all course code files in the compilation
– List of compiler option used in the compilation
– Version information about the compiler, run time and operating system
– Output generated by the compiler
• They contain the types and resources that make up an application and
describe those contained types to the CLR.
TestDLL
TestAssembly
MyAssembly
• Consists of
- Name of assembly
- Version number
- Public key of public/private key pair
• Step 1 : In the .Net IDE, from the File menu, choose New and then choose
Project. The New Project window opens.
• Step 2 : In the New Project window, select Visual C# Projects, and then
choose Class Library .Specify name as TestLib and path as
C:\SharedAssembly
(Please a create the folder SharedAssembly before)
namespace TestLib
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class MathsFunction
{
public MathsFunction()
{
//
// TODO: Add constructor logic here
//
}
public int multiply(int x, int y)
{
return x*y;
}
}
}
• Step 1: In the .Net IDE, from the File menu, choose New and then choose
Project. The New Project window opens.
• Step 2: In the New Project window, select Visual C# Projects, and then choose
Console Application and name it as TestClient.
• Step 3: From Project menu, select Add Reference to the above created dll
(thru Browse).
(dll would be present in the following path –
C:\SharedAssembly\TestLib\bin\debug\TestLib.dll)
namespace TestClient
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
TestLib.MathsFunction obj = new TestLib.MathsFunction ();
Console.WriteLine (obj.multiply(5,5));
}
}
}
• Step 3 : Rebuild the class library and publish again using gacutil.
• Step 2: From Project Menu, selct Add - > New Item -> Application
Configuration File and click on Open. App.config is added.
• Step 3 : Click on Start->All Programs -> Microsoft .NET SDK FrameWork ->
Documentation.
• Step 5: From the given example copy and paste the entire contents between
<configuration></configuration> in App.config.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
• Step 7 : Change public key token. For it thru Windows Explorer, move to location
c:\Windows\assembly and select TestLib.
• Step 8: Right Click on TestLib and select Properties.Copy and Paste public key token in
App.config file.
• Step 9 : Rebuild application. Run TestClient.exe from the .NET command prompt and
path C:\SharedAssembly\TestClient\bin\debug. Version 2.0 will be used.
• Step 10: In order to use,Version 1.0,open App.config and interchange old and new
version.
• Step 11 : Rebuild application. Run TestClient.exe from the .NET command prompt and
path C:\SharedAssembly\TestClient\bin\debug. Version 1.0 will be used.
• Properties
• Indexers
• Collections
• Compiler Switches
• Assemblies
– Private
– Public
– Versioning