Can we add different class to first row and last row of view?
You would probably be fine with just doing this with css ( see Beebee's comment on your post), but I will answer the question.

You can use loop.first and loop.last in twig. Here is an example I used to make it work in a menu.

&lt;ul class="menu"&gt;
    {% for item in items %}
        {%
            set classes = [
            'menu-item',
            item.is_expanded ? 'menu-item--expanded',
            item.is_collapsed ? 'menu-item--collapsed',
            item.in_active_trail ? 'menu-item--active-trail',
        ]
        %}
        {% if loop.first %}
            &lt;li {{ item.attributes.addClass('first-element') }}&gt;
               {{ link(item.title, item.url) }}
               {% if item.below %}
                  {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
               {% endif %}
            &lt;/li&gt;
        {% endif %}
        {% if loop.last %}
            &lt;li{{ item.attributes.addClass('last-element') }}&gt;
                {{ link(item.title, item.url) }}
                {% if item.below %}
                    {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
                {% endif %}
            &lt;/li&gt;
        {% else %}
            &lt;li{{ item.attributes.addClass(classes) }}&gt;
                {{ link(item.title, item.url) }}
                {% if item.below %}
                    {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
                {% endif %}
            &lt;/li&gt;
        {% endif %}

    {% endfor %}
&lt;/ul&gt;