Showing category "c#" (Show all posts)

The four basic principles of object-oriented programming (c#)

Posted by jineesh uvantavida on Monday, June 7, 2021, In : c# 
  •  Abstraction 
    1. Abstraction is "To represent the essential feature without representing the background details."
    2. Abstraction lets you focus on what the object does instead of how it does it.
    3. Abstraction provides you a generalized view of your classes or objects by providing relevant information
    4. Abstraction is the process of hiding the working style of an object, and showing the information of an object in an understandable manner.
  • Encapsulation 
    1. Hiding the internal state and functionality of an objec...

Continue reading ...
 

Serialize an object in c# with XmlSerializer by removing xml schema elements.

Posted by jineesh uvantavida on Tuesday, November 14, 2017, In : c# 
Serialize an object in c# with XmlSerializer by removing xml schema elements such as xmlns:xsi

        string content =String.Empty;
XmlDocument xmlDoc = new XmlDocument();
        XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
        using (MemoryStream xmlStream = new MemoryStream())
        {
            var ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            xmlSerializer.Serialize(xmlStream, obj, ns);
            xmlStream.Position = 0;
            //Load...

Continue reading ...
 

Configuration to be done for Activation of WCF Service

Posted by jineesh uvantavida on Tuesday, November 14, 2017, In : c# 
The below configuation to be added in the web.config or app.config for the proper functioning of WCF Service.


 <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Service1_Behavior">
          <serviceMetadata httpGetEnabled="True"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="Namespace1.Service1"
               behaviorConfiguration="Service1_Behavior">
        <endpoint address="url of wcf service created" binding...

Continue reading ...
 

Generating Unique ID in C# - Best Method.

Posted by jineesh uvantavida on Friday, November 10, 2017, In : c# 

We can use DateTime.Now.Ticks and Guid.NewGuid().ToString() to combine together and make a unique id.

As the DateTime.Now.Ticks is added, we can find out the Date and Time in seconds at which the unique id is created.

Please see the code.

var ticks = DateTime.Now.Ticks;
var guid = Guid.NewGuid().ToString();
var uniqueSessionId = ticks.ToString() +'-'+ guid; //guid created by combining ticks and guid

var datetime = new DateTime(ticks);//for checking purpose
var datetimenow = DateTime.Now;    //b...

Continue reading ...
 

How can we limit the length of a string to 150 characters?

Posted by jineesh uvantavida on Friday, November 10, 2017, In : c# 

It will be good if your environment support you to use below method.

[StringLength(150)]
public string MyProperty { get; set; }

You have to include the below namespace to use it.

using System.ComponentModel.DataAnnotations;

Continue reading ...
 

What is the difference between String and string in C#?

Posted by jineesh uvantavida on Friday, November 10, 2017, In : c# 

string is a sequential collection of characters that is used to represent text.

String object is a sequential collection of System.Char objects that represent a string; a System.Char object corresponds to a UTF-16 code unit.

The value of the String object is the content of the sequential collection of System.Char objects, and that value is immutable (that is, it is read-only).

For more information about the immutability of strings, see the Immutability and the StringBuilder class section in ...


Continue reading ...
 
 

Translate This Page

 


Make a free website with Yola