Thursday, 12 September 2013

CSHARP DOTNET WINDOWS STORE APPS MANOHAR GOUD


.NET for Windows Store apps overview


The .NET Framework provides a subset of managed types that you can use to create Windows Store apps using C# or Visual Basic. This subset of managed types is called the .NET for Windows Store apps and enables .NET Framework developers to create Windows Store apps within a familiar programming framework. Any types that are not related to developing Windows Store apps are not included in the subset.
You use these managed types with types from the Windows Runtime API to create Windows Store apps. Typically, you won't notice any differences between using the managed types and the Windows Runtime types except that the managed types reside in namespaces that start with System, and the Windows Runtime types reside in namespaces that start with Windows. Together, the .NET for Windows Store apps and the Windows Runtime provide the complete set of types and members available for developing Windows Store apps with C# or Visual Basic.
The subset of managed types and members was designed with a clear focus on Windows Store app development. As a result, it omits the following:
  • Types and members that are not applicable to developing Windows Store apps (such as console and ASP.NET types).
  • Obsolete and legacy types.
  • Types that overlap with Windows Runtime types.
  • Types and members that wrap operating system functionality (such as System.Diagnostics.EventLog and performance counters).
  • Members that cause confusion (such as the Close method on I/O types).
In some cases, a type that you used in a .NET Framework desktop app doesn't exist within the .NET for Windows Store apps. Instead, you can use a type from the Windows Runtime. For example, the System.IO.IsolatedStorage.IsolatedStorageSettings class isn't included in the .NET for Windows Store apps, but the Windows.Storage.ApplicationDataContainer class provides similar behavior for storing app settings. .
The entire set of assemblies for the .NET for Windows Store apps is automatically referenced in your project when you create a Windows Store app using C# or Visual Basic. Therefore, you can use any of the types supported by the .NET for Windows Store apps in your project without any additional actions. For a list of the combined namespaces provided by the .NET for Windows Store apps and the Windows Runtime (grouped by functional area).
For a list of namespaces and types included in the .NET Framework subset, 
You can also create a Portable Class Library project to develop a .NET Framework library that can be used from a Windows Store app. The project must include.NET for Windows Store apps as one of the target platforms. The Portable Class Library is particularly useful when you want to develop classes that can be used from apps for different types of platforms, such as a Windows Phone app, desktop app, and Windows Store app. 
This topic includes the following sections:
  • Converting your existing .NET Framework code
  • Extension methods for converting types
  • .NET Framework and Windows Runtime namespaces

Typically, you do not simply convert an existing .NET Framework app to a Windows Store app; you redesign the .NET Framework app for the new user experience. However, you may want to convert parts of an existing .NET Framework app for use in a new Windows Store app. When you convert existing .NET Framework code, you should be aware of the following changes you may need to make in your Windows Store app:
  • UI changes
  • I/O changes
  • Storage changes
  • Networking changes
  • Threading changes
  • Reflection changes
  • Security changes
  • Resource changes
  • Exception changes
  • WCF changes
  • Changes in general .NET Framework types

BR230302.collapse_all(en-us,VS.110).gifUI changes

When you convert UI code from a Silverlight-based app or Windows Phone app, you can use many of the same UI types, but the types are now located in the Windows.UI.Xaml namespaces instead of the System.Windows namespaces. These new UI types are similar to the previous .NET Framework UI types but contain some different members.
Replace
With
UI types in System.Windows.* namespaces
UI types in Windows.UI.Xaml.* namespaces
(for example, the Border class is located in the Windows.UI.Xaml.Controls namespace)

BR230302.collapse_all(en-us,VS.110).gifI/O changes

The I/O types include new members to support the new await keyword in the asynchronous programming model.
Replace
With
System.IO.Stream.BeginRead and EndRead methods
System.IO.Stream.ReadAsync method

System.IO.Stream.BeginWrite and EndWrite methods
System.IO.Stream.WriteAsync method

Close() method on I/O classes
Dispose() method on I/O classes.
-or-
Declare and instantiate the I/O object within a using (C#) or Using (Visual Basic) statement to ensure that it is properly disposed; for example:
using (StreamReader sr = 
  new StreamReader(await passedFile.OpenStreamForReadAsync()))
{
    while ((nextLine = await sr.ReadLineAsync()) != null)
    {
        contents.Append(nextLine);
    }
}

System.IO.File.ReadAllText method
The ReadTextAsync method in the Windows.Storage.PathIO class
Code to retrieve and open a file
public static async void ReadFileSamples()
{
  // Read a file from package
  StorageFolder packageFolder = 
      ApplicationModel.Package.Current.InstalledLocation;
  StorageFile packagedFile = 
      await packageFolder.GetFileAsync("FileInPackage");

  // Read a file from AppData
  StorageFolder localFolder = ApplicationData.Current.LocalFolder;
  StorageFile localFile = 
    await localFolder.GetFileAsync("FileInAppData");
}

BR230302.collapse_all(en-us,VS.110).gifStorage changes

Instead of using the System.IO.IsolatedStorage class, use the types in the Windows.Storage namespaces to store local data and files.
Replace
With
System.IO.IsolatedStorage.IsolatedStorageFile class
The LocalFolder property on the Windows.Storage.ApplicationData class
ApplicationData.Current.LocalFolder
System.IO.IsolatedStorage.IsolatedStorageSettings class
The LocalSettings property on the Windows.Storage.ApplicationData class
ApplicationData.Current.LocalSettings

BR230302.collapse_all(en-us,VS.110).gifNetworking changes

Replace
With
System.Net.WebClient class
System.Net.Http.HttpClient class for sending HTTP requests and receiving HTTP responses
-or-
Types in the Windows.Networking.BackgroundTransfer namespace to upload or download large amounts of data
Types in the System.Net.Sockets namespace
Types in the Windows.Networking.Sockets namespace
Relative URIs, when passed to Windows Runtime types
Absolute URIs

Exception handling code that catches the UriFormatException exception
Code that catches the FormatException exception, which is the parent class of UriFormatException

BR230302.collapse_all(en-us,VS.110).gifThreading changes

Some of the .NET Framework threading members have changed, and some types are now available in the Windows Runtime API.
Replace
With
System.Threading.Thread.MemoryBarrier method
Interlocked.MemoryBarrier method in the System.Threading namespace
System.Threading.Thread.ManagedThreadId property
Environment.CurrentManagedThreadId property in the System namespace
System.Threading.Thread.CurrentCulture property
CultureInfo.CurrentCulture property in the System.Globalization namespace
System.Threading.Thread.CurrentUICulture property
CultureInfo.CurrentUICulture property in the System.Globalization namespace
System.Threading.Timer class
Windows.System.Threading.ThreadPoolTimer class
System.Threading.ThreadPool class
Windows.System.Threading.ThreadPool class
Code that queues work to the pool
Task.Run(() => 
{ 
  // work goes here
});
Code that queues work to the pool and waits for completion
await Task.Run(() => 
{ 
  // work goes here
});
Code that creates a long-running work item
Task.Factory.StartNew(() => 
{ 
  // work goes here
}, TaskCreationOptions.LongRunning);

BR230302.collapse_all(en-us,VS.110).gifReflection changes

Most members from the System.Type class have been moved to the System.Reflection.TypeInfo class. You can retrieve the TypeInfo object by calling the System.Reflection.IntrospectionExtensions.GetTypeInfo(System.Type) method, which is an extension method for Type.
Replace
With
type.Assembly
type.GetTypeInfo().Assembly
type.GetMethods(BindingFlags.DeclaredOnly)
type.GetTypeInfo().DeclaredMethods
type.GetMethod("MethodName", BindingFlags.DeclaredOnly)
type.GetTypeInfo().GetDeclaredMethod("MethodName")
type.GetNestedTypes()
type.GetTypeInfo().DeclaredNestedTypes
System.Delegate.CreateDelegate method
MethodInfo.CreateDelegate method

BR230302.collapse_all(en-us,VS.110).gifSecurity changes

Many of the types for security, authentication, and cryptography operations are available through Windows Runtime types. For a complete list of the security namespaces that are available for Windows Store apps, see the security namespaces list later in this topic.

BR230302.collapse_all(en-us,VS.110).gifResource changes

For Windows Store apps, you create a single resource file instead of the hub-and-spoke model that is used in desktop apps. In addition, use the resource types in the Windows.ApplicationModel.Resources and Windows.ApplicationModel.Resources.Core namespaces instead of the System.Resources namespace.

BR230302.collapse_all(en-us,VS.110).gifException changes

In some cases, a managed type throws an exception that is not included in the .NET for Windows Store apps. In these cases, you can catch the parent class of the exception that is not included. For example, in a desktop app, you catch the UriFormatException exception to handle an invalid URI; but in a Windows Store app, you catch the FormatException exception because UriFormatException is not included in the .NET for Windows Store apps.FormatException is the parent class of UriFormatException.

BR230302.collapse_all(en-us,VS.110).gifWCF changes

In Windows Store apps, you can utilize Windows Communication Foundation (WCF) client functionality to retrieve data from a WCF service, but you cannot create a WCF service to serve data.

BR230302.collapse_all(en-us,VS.110).gifChanges in general .NET Framework types

Replace
With
System.Xml.XmlConvert.ToDateTime method
XmlConvert.ToDateTimeOffset method
System.ICloneable interface
A custom method that returns the appropriate type
System.Array.AsReadOnly and System.Collections.Generic.List<T>.AsReadOnly methods
A new instance of the System.Collections.ObjectModel.ReadOnlyCollection<T>class, created as follows:
new ReadOnlyCollection<string>(selectedList)










Tuesday, 3 September 2013

CSHARP CODER MANOHAR GOUD


CSHARP CODER MANOHAR GOUD

using System;
using System.IO;

public class ManualRelease
{
    static void Main() 
    {
        StreamReader sr = null;

        try
        {
            sr = new StreamReader("languages");
            Console.WriteLine(sr.ReadToEnd());

        } catch (IOException e)
        {
            Console.WriteLine("Cannot read file");
            Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
            Console.WriteLine("Cannot access file");
            Console.WriteLine(e.Message);

        } finally 
        {
            if (sr != null) sr.Dispose();
        }
    }
}

using System;
using System.IO;

public class AutomaticCleanup
{
    static void Main() 
    {
        try
        {
            using (StreamReader sr = new StreamReader("languages"))
            {
                Console.WriteLine(sr.ReadToEnd());
            }            

        } catch (IOException e)
        {
            Console.WriteLine("Cannot read file");
            Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
            Console.WriteLine("Cannot access file");
            Console.WriteLine(e.Message);
        }
    }
}


using System;
using System.IO;

public class MemoryStreamExample
{
    static void Main()
    {
        try
        {
            using(Stream ms = new MemoryStream(6))
            {

                ms.WriteByte(9);
                ms.WriteByte(11);
                ms.WriteByte(6);
                ms.WriteByte(8);
                ms.WriteByte(3);
                ms.WriteByte(7);

                ms.Position = 0;

                int rs = ms.ReadByte();

                do 
                {
                    Console.WriteLine(rs);
                    rs = ms.ReadByte();                    

                } while (rs != -1);
            }

        } catch (IOException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}


using System;
using System.IO;

public class ReadFile
{
    static void Main() 
    {     
       try
       {
           using(StreamReader stream = new StreamReader("languages"))
           {
               Console.WriteLine(stream.ReadToEnd());
           }

       } catch (IOException e)
       {
           Console.WriteLine("Cannot read file");
           Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
           Console.WriteLine("Cannot access file");
           Console.WriteLine(e.Message);
        }  
    }
}


using System;
using System.IO;

public class CountingLines
{
    static void Main() 
    {
        int count = 0;

        try
        {           
           using (StreamReader stream = new StreamReader("languages"))
           {
               while(stream.ReadLine() != null)
               {
                   count++;
               }

               Console.WriteLine("There are {0} lines", count);
           } 

        } catch (IOException e)
        {
            Console.WriteLine("Cannot read file.");
            Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
           Console.WriteLine("Cannot access file");
           Console.WriteLine(e.Message);
        }
    }
}


using System;
using System.IO;

public class CSharpApp
{
    static void Main() 
    {
        try 
        {
            using (MemoryStream ms = new MemoryStream())
            { 
                using (StreamWriter swriter = new StreamWriter(ms))
                {
                    swriter.Write("ZetCode, tutorials for programmers.");
                    swriter.Flush();
                            
                    ms.Position = 0;

                    using (StreamReader sreader = new StreamReader(ms))
                    {
                        Console.WriteLine(sreader.ReadToEnd());
                    } 
                }
            }

        } catch (IOException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}


using System;
using System.IO;
using System.Text;

public class FileStreamExample
{
    static void Main() 
    {
        try
        {
            using (FileStream fstream = new FileStream("author", FileMode.Append))
            {
                string text = "Фёдор Михайлович Достоевский";
                byte[] bytes = new UTF8Encoding().GetBytes(text);

                fstream.Write(bytes, 0, bytes.Length);
            }

        } catch (IOException e)
        {
            Console.WriteLine("Cannot write to file");
            Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
           Console.WriteLine("Cannot access file");
           Console.WriteLine(e.Message);
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<languages>
    <language>Python</language>
    <language>Ruby</language>   
    <language>Javascript</language>
    <language>C#</language>
</languages>

using System;
using System.IO;
using System.Xml;

public class ReadingXMLFile
{
    static void Main() 
    {       
        string file = "languages.xml";
      
        try
        {
            using (XmlTextReader xreader = new XmlTextReader(file))
            {
                xreader.MoveToContent();

                while (xreader.Read())
                {
                    switch (xreader.NodeType)
                    {
                        case XmlNodeType.Element:
                            Console.Write(xreader.Name + ": ");
                            break;

                        case XmlNodeType.Text:
                            Console.WriteLine(xreader.Value); 
                            break;
                    }
                }
            } 
 
        } catch (IOException e)
        {
            Console.WriteLine("Cannot read file.");
            Console.WriteLine(e.Message);

        } catch (XmlException e)
        {
            Console.WriteLine("XML parse error");
            Console.WriteLine(e.Message);
        }
    }
}

using System;
using System.IO;

public class CreateDirectory
{
    static void Main() 
    {
        try
        {
            Directory.CreateDirectory("temp");
            Directory.CreateDirectory("newdir");
            Directory.Move("temp", "temporary");

        } catch (IOException e)
        {
            Console.WriteLine("Cannot create directory");
            Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
           Console.WriteLine("Cannot access directory");
           Console.WriteLine(e.Message);
        }
    }
}

using System;
using System.IO;

public class ShowContents
{
    static void Main() 
    {
        try 
        {
            DirectoryInfo dir = new DirectoryInfo("test");

            string[] files = Directory.GetFiles("test");
            DirectoryInfo[] dirs = dir.GetDirectories();
            
            foreach (DirectoryInfo subDir in dirs)
            {
                Console.WriteLine(subDir.Name);
            }

            foreach (string fileName in files)
            {
                Console.WriteLine(fileName);
            }

        } catch (IOException e)
        {
            Console.WriteLine("IO exception");
            Console.WriteLine(e.Message);

        } catch (UnauthorizedAccessException e)
        {
           Console.WriteLine("Cannot access file");
           Console.WriteLine(e.Message);
        }        
    }
}

using System;
using System.IO;

public class CopyFile
{
    static void Main() 
    {
       try
       {        
            if (File.Exists("cars"))
            {
                Console.WriteLine(File.GetCreationTime("cars"));
                Console.WriteLine(File.GetLastWriteTime("cars"));
                Console.WriteLine(File.GetLastAccessTime("cars"));
            }

            File.Copy("cars", "newcars");

       } catch (IOException e)
       {
           Console.WriteLine("IO error");
           Console.WriteLine(e.Message);
       }
    }
}

CSHARP CODER PROGRAMMER DEVELOPER BEGINNERS AND ADVANCE MANOHAR GOUD FACULTY GURU

CSHARP BEGINNER AND ADVANCE EXAMPLES

using System;

public class Simple
{
    static void Main()
    {
        Console.WriteLine("This is MANOHAR GOUD");
    }
}


using System;

public class ReadLine
{
    static void Main()
    {
        string name;

        Console.Write("Enter your name: ");
        name = Console.ReadLine();
        Console.WriteLine("Hello {0}", name);
    }
}

using System;

public class CSharpApp 
{
    static void Main(string[] args) 
    {
        for (int i=0; i<args.Length; i++) 
        {
            Console.WriteLine("{0}", args[i]);
        }
    }
}

using System;

public class CSharpApp
{
    static void Main()
    {
        string city = "SEC BAD";
        string name = "MANOHAR GOUD"; int age = 35;
        string nationality = "INDIAN";

        Console.WriteLine(city);
        Console.WriteLine(name);
        Console.WriteLine(age);
        Console.WriteLine(nationality);

        city = "HYDERABAD";
        Console.WriteLine(city);
    }
}

using System;

public class Constants
{
    static void Main()
    {
        const int WIDTH = 100;
        const int HEIGHT= 150;
        int var = 40;

        var = 50;

        // WIDTH = 110;
    }
}

using System;

public class StringFormatting
{
    static void Main()
    {
        int age = 34;
        string name = "MANOHAR GOUD";
        string output;

        output = string.Format("{0} is {1} years old.", 
            name, age);
        Console.WriteLine(output);
    }
}


using System;

public struct Point
{
    private int x;
    private int y;

    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }

    public override string ToString()
    {
        return String.Format("Point, x:{0}, y:{1}", x, y);
    }
}

public class SimpleStructure
{
    static void Main()
    {
        Point p = new Point(2, 5);
        Console.WriteLine(p);        
    }
}

using System;

public struct Person 
{
    public string name; 
    public int age;
}

public class StructureExample
{
    static void Main()
    {
        Person p;
        p.name = "MANOHAR GOUD";
        p.age = 17;

        Console.WriteLine("{0} is {1} years old", 
            p.name, p.age);        
    }
}

using System;

public struct Person 
{
    public Person(string name, int age)
    {
        this.Name = name;
        this.Age = age;
    }

    public string Name { get; set; }

    public int Age { get; set; }

    public override string ToString()
    {
        return String.Format("{0} is {1} years old", Name, Age);
    }
}

public class ValueTypes
{
    static void Main()
    {
        Person p1 = new Person("MANOHAR GOUD", 18);
        Person p2 = p1;

        Console.WriteLine(p2); 
        p2.Name = "ANIRUDH GOUD";
        p2.Age = 17;

        Console.WriteLine(p2); 
        Console.WriteLine(p1);           
    }
}


using System;

public class PrimitiveTypes
{
    static void Main()
    {
        float x = 12.3f;
        int y = 34;
        bool z = false;

        Console.WriteLine(x.GetType());
        Console.WriteLine(y.GetType());
        Console.WriteLine(z.GetType());
    }
}






The first example shows you how to declare and use structs,

This example declares a struct with three members: a property, a method, and a private field. It creates an instance of the struct and puts it to use:

// struct1.cs
using System;
struct SimpleStruct
{
    private int xval;
    public int X
    {
        get 
        {
            return xval;
        }
        set 
        {
            if (value < 100)
                xval = value;
        }
    }
    public void DisplayX()
    {
        Console.WriteLine("The stored value is: {0}", xval);
    }
}

class TestClass
{
    public static void Main()
    {
        SimpleStruct ss = new SimpleStruct();
        ss.X = 5;
        ss.DisplayX();
    }
}

OUTPUT
The stored value is: 5

Example 2

This example shows that when a struct is passed to a method, a copy of the struct is passed, but when a class instance is passed, a reference is passed.

// struct2.cs
using System;

class TheClass
{
    public int x;
}

struct TheStruct
{
    public int x;
}

class TestClass
{
    public static void structtaker(TheStruct s)
    {
        s.x = 5;
    }
    public static void classtaker(TheClass c)
    {
        c.x = 5;
    }
    public static void Main()
    {
        TheStruct a = new TheStruct();
        TheClass b = new TheClass();
        a.x = 1;
        b.x = 1;
        structtaker(a);
        classtaker(b);
        Console.WriteLine("a.x = {0}", a.x);
        Console.WriteLine("b.x = {0}", b.x);
    }
}

OUTPUT
a.x = 1
b.x = 5